提交 376e30ae 编写于 作者: Y Yifan Hao

Hash table cleanup [2/n]

A few cleanups:
1. Rename hash node "count" to "refCount" for ease of reading
2. Trailing white space removal of hash.h
上级 5af1acaa
...@@ -36,7 +36,7 @@ typedef struct SHashNode { ...@@ -36,7 +36,7 @@ typedef struct SHashNode {
uint32_t dataLen; // length of data uint32_t dataLen; // length of data
uint32_t keyLen; // length of the key uint32_t keyLen; // length of the key
int8_t removed; // flag to indicate removed int8_t removed; // flag to indicate removed
int32_t count; // reference count int32_t refCount; // reference count
char data[]; char data[];
} SHashNode; } SHashNode;
...@@ -81,9 +81,9 @@ SHashObj *taosHashInit(size_t capacity, _hash_fn_t fn, bool update, SHashLockTyp ...@@ -81,9 +81,9 @@ SHashObj *taosHashInit(size_t capacity, _hash_fn_t fn, bool update, SHashLockTyp
/** /**
* set equal func of the hash table * set equal func of the hash table
* @param pHashObj * @param pHashObj
* @param equalFp * @param equalFp
* @return * @return
*/ */
void taosHashSetEqualFp(SHashObj *pHashObj, _equal_fn_t fp); void taosHashSetEqualFp(SHashObj *pHashObj, _equal_fn_t fp);
...@@ -133,7 +133,7 @@ void* taosHashGetClone(SHashObj *pHashObj, const void *key, size_t keyLen, void ...@@ -133,7 +133,7 @@ void* taosHashGetClone(SHashObj *pHashObj, const void *key, size_t keyLen, void
* @param keyLen * @param keyLen
* @param fp * @param fp
* @param d * @param d
* @param sz * @param sz
* @return * @return
*/ */
void* taosHashGetCloneExt(SHashObj *pHashObj, const void *key, size_t keyLen, void (*fp)(void *), void** d, size_t *sz); void* taosHashGetCloneExt(SHashObj *pHashObj, const void *key, size_t keyLen, void (*fp)(void *), void** d, size_t *sz);
......
...@@ -119,14 +119,14 @@ static SHashNode *doCreateHashNode(const void *key, size_t keyLen, const void *p ...@@ -119,14 +119,14 @@ static SHashNode *doCreateHashNode(const void *key, size_t keyLen, const void *p
static FORCE_INLINE SHashNode *doUpdateHashNode(SHashObj *pHashObj, SHashEntry* pe, SHashNode* prev, SHashNode *pNode, SHashNode *pNewNode) { static FORCE_INLINE SHashNode *doUpdateHashNode(SHashObj *pHashObj, SHashEntry* pe, SHashNode* prev, SHashNode *pNode, SHashNode *pNewNode) {
assert(pNode->keyLen == pNewNode->keyLen); assert(pNode->keyLen == pNewNode->keyLen);
atomic_sub_fetch_32(&pNode->count, 1); atomic_sub_fetch_32(&pNode->refCount, 1);
if (prev != NULL) { if (prev != NULL) {
prev->next = pNewNode; prev->next = pNewNode;
} else { } else {
pe->next = pNewNode; pe->next = pNewNode;
} }
if (pNode->count <= 0) { if (pNode->refCount <= 0) {
pNewNode->next = pNode->next; pNewNode->next = pNode->next;
DO_FREE_HASH_NODE(pNode); DO_FREE_HASH_NODE(pNode);
} else { } else {
...@@ -464,9 +464,9 @@ int32_t taosHashRemoveWithData(SHashObj *pHashObj, const void *key, size_t keyLe ...@@ -464,9 +464,9 @@ int32_t taosHashRemoveWithData(SHashObj *pHashObj, const void *key, size_t keyLe
if (pNode) { if (pNode) {
code = 0; // it is found code = 0; // it is found
atomic_sub_fetch_32(&pNode->count, 1); atomic_sub_fetch_32(&pNode->refCount, 1);
pNode->removed = 1; pNode->removed = 1;
if (pNode->count <= 0) { if (pNode->refCount <= 0) {
if (prevNode) { if (prevNode) {
prevNode->next = pNode->next; prevNode->next = pNode->next;
} else { } else {
...@@ -756,7 +756,7 @@ SHashNode *doCreateHashNode(const void *key, size_t keyLen, const void *pData, s ...@@ -756,7 +756,7 @@ SHashNode *doCreateHashNode(const void *key, size_t keyLen, const void *pData, s
pNewNode->keyLen = (uint32_t)keyLen; pNewNode->keyLen = (uint32_t)keyLen;
pNewNode->hashVal = hashVal; pNewNode->hashVal = hashVal;
pNewNode->dataLen = (uint32_t) dsize; pNewNode->dataLen = (uint32_t) dsize;
pNewNode->count = 1; pNewNode->refCount = 1;
pNewNode->removed = 0; pNewNode->removed = 0;
pNewNode->next = NULL; pNewNode->next = NULL;
...@@ -825,8 +825,8 @@ static void *taosHashReleaseNode(SHashObj *pHashObj, void *p, int *slot) { ...@@ -825,8 +825,8 @@ static void *taosHashReleaseNode(SHashObj *pHashObj, void *p, int *slot) {
pNode = pNode->next; pNode = pNode->next;
} }
atomic_sub_fetch_32(&pOld->count, 1); atomic_sub_fetch_32(&pOld->refCount, 1);
if (pOld->count <=0) { if (pOld->refCount <=0) {
if (prevNode) { if (prevNode) {
prevNode->next = pOld->next; prevNode->next = pOld->next;
} else { } else {
...@@ -891,7 +891,7 @@ void *taosHashIterate(SHashObj *pHashObj, void *p) { ...@@ -891,7 +891,7 @@ void *taosHashIterate(SHashObj *pHashObj, void *p) {
if (pNode) { if (pNode) {
SHashEntry *pe = pHashObj->hashList[slot]; SHashEntry *pe = pHashObj->hashList[slot];
atomic_add_fetch_32(&pNode->count, 1); atomic_add_fetch_32(&pNode->refCount, 1);
data = GET_HASH_NODE_DATA(pNode); data = GET_HASH_NODE_DATA(pNode);
if (pHashObj->type == HASH_ENTRY_LOCK) { if (pHashObj->type == HASH_ENTRY_LOCK) {
taosWUnLockLatch(&pe->latch); taosWUnLockLatch(&pe->latch);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册