Merge pull request #3551 from hugovk/rm-quanthash-destroy-funcs

Remove unused C hashtable functions
This commit is contained in:
Andrew Murray 2019-03-16 21:48:49 +11:00 committed by GitHub
commit 406d1d4b9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 0 additions and 144 deletions

View File

@ -35,8 +35,6 @@ struct _HashTable {
uint32_t count;
HashFunc hashFunc;
HashCmpFunc cmpFunc;
KeyDestroyFunc keyDestroyFunc;
ValDestroyFunc valDestroyFunc;
void *userData;
};
@ -51,8 +49,6 @@ HashTable *hashtable_new(HashFunc hf,HashCmpFunc cf) {
if (!h) { return NULL; }
h->hashFunc=hf;
h->cmpFunc=cf;
h->keyDestroyFunc=NULL;
h->valDestroyFunc=NULL;
h->length=MIN_LENGTH;
h->count=0;
h->userData=NULL;
@ -62,15 +58,6 @@ HashTable *hashtable_new(HashFunc hf,HashCmpFunc cf) {
return h;
}
static void _hashtable_destroy(const HashTable *h,const HashKey_t key,const HashVal_t val,void *u) {
if (h->keyDestroyFunc) {
h->keyDestroyFunc(h,key);
}
if (h->valDestroyFunc) {
h->valDestroyFunc(h,val);
}
}
static uint32_t _findPrime(uint32_t start,int dir) {
static int unit[]={0,1,0,1,0,0,0,1,0,1,0,1,0,1,0,0};
uint32_t t;
@ -144,12 +131,6 @@ static int _hashtable_insert_node(HashTable *h,HashNode *node,int resize,int upd
free(node);
return 1;
} else {
if (h->valDestroyFunc) {
h->valDestroyFunc(h,nv->value);
}
if (h->keyDestroyFunc) {
h->keyDestroyFunc(h,nv->key);
}
nv->key=node->key;
nv->value=node->value;
free(node);
@ -180,7 +161,6 @@ static int _hashtable_insert(HashTable *h,HashKey_t key,HashVal_t val,int resize
nv=*n;
i=h->cmpFunc(h,nv->key,key);
if (!i) {
if (h->valDestroyFunc) { h->valDestroyFunc(h,nv->value); }
nv->value=val;
return 1;
} else if (i>0) {
@ -202,34 +182,6 @@ static int _hashtable_insert(HashTable *h,HashKey_t key,HashVal_t val,int resize
}
}
static int _hashtable_lookup_or_insert(HashTable *h,HashKey_t key,HashVal_t *retVal,HashVal_t newVal,int resize) {
HashNode **n,*nv;
HashNode *t;
int i;
uint32_t hash=h->hashFunc(h,key)%h->length;
for (n=&(h->table[hash]);*n;n=&((*n)->next)) {
nv=*n;
i=h->cmpFunc(h,nv->key,key);
if (!i) {
*retVal=nv->value;
return 1;
} else if (i>0) {
break;
}
}
t=malloc(sizeof(HashNode));
if (!t) return 0;
t->next=*n;
*n=t;
t->key=key;
t->value=newVal;
*retVal=newVal;
h->count++;
if (resize) _hashtable_resize(h);
return 1;
}
int hashtable_insert_or_update_computed(HashTable *h,
HashKey_t key,
ComputeFunc newFunc,
@ -243,14 +195,8 @@ int hashtable_insert_or_update_computed(HashTable *h,
nv=*n;
i=h->cmpFunc(h,nv->key,key);
if (!i) {
HashVal_t old=nv->value;
if (existsFunc) {
existsFunc(h,nv->key,&(nv->value));
if (nv->value!=old) {
if (h->valDestroyFunc) {
h->valDestroyFunc(h,old);
}
}
} else {
return 0;
}
@ -275,10 +221,6 @@ int hashtable_insert_or_update_computed(HashTable *h,
return 1;
}
int hashtable_update(HashTable *h,HashKey_t key,HashVal_t val) {
return _hashtable_insert(h,key,val,1,0);
}
int hashtable_insert(HashTable *h,HashKey_t key,HashVal_t val) {
return _hashtable_insert(h,key,val,1,0);
}
@ -314,9 +256,6 @@ void hashtable_free(HashTable *h) {
uint32_t i;
if (h->table) {
if (h->keyDestroyFunc || h->keyDestroyFunc) {
hashtable_foreach(h,_hashtable_destroy,NULL);
}
for (i=0;i<h->length;i++) {
for (n=h->table[i];n;n=nn) {
nn=n->next;
@ -328,84 +267,10 @@ void hashtable_free(HashTable *h) {
free(h);
}
ValDestroyFunc hashtable_set_value_destroy_func(HashTable *h,ValDestroyFunc d) {
ValDestroyFunc r=h->valDestroyFunc;
h->valDestroyFunc=d;
return r;
}
KeyDestroyFunc hashtable_set_key_destroy_func(HashTable *h,KeyDestroyFunc d) {
KeyDestroyFunc r=h->keyDestroyFunc;
h->keyDestroyFunc=d;
return r;
}
static int _hashtable_remove(HashTable *h,
const HashKey_t key,
HashKey_t *keyRet,
HashVal_t *valRet,
int resize) {
uint32_t hash=h->hashFunc(h,key)%h->length;
HashNode *n,*p;
int i;
for (p=NULL,n=h->table[hash];n;p=n,n=n->next) {
i=h->cmpFunc(h,n->key,key);
if (!i) {
if (p) p=n->next; else h->table[hash]=n->next;
*keyRet=n->key;
*valRet=n->value;
free(n);
h->count++;
return 1;
} else if (i>0) {
break;
}
}
return 0;
}
static int _hashtable_delete(HashTable *h,const HashKey_t key,int resize) {
uint32_t hash=h->hashFunc(h,key)%h->length;
HashNode *n,*p;
int i;
for (p=NULL,n=h->table[hash];n;p=n,n=n->next) {
i=h->cmpFunc(h,n->key,key);
if (!i) {
if (p) p=n->next; else h->table[hash]=n->next;
if (h->valDestroyFunc) { h->valDestroyFunc(h,n->value); }
if (h->keyDestroyFunc) { h->keyDestroyFunc(h,n->key); }
free(n);
h->count++;
return 1;
} else if (i>0) {
break;
}
}
return 0;
}
int hashtable_remove(HashTable *h,const HashKey_t key,HashKey_t *keyRet,HashVal_t *valRet) {
return _hashtable_remove(h,key,keyRet,valRet,1);
}
int hashtable_delete(HashTable *h,const HashKey_t key) {
return _hashtable_delete(h,key,1);
}
void hashtable_rehash_compute(HashTable *h,CollisionFunc cf) {
_hashtable_rehash(h,cf,h->length);
}
void hashtable_rehash(HashTable *h) {
_hashtable_rehash(h,NULL,h->length);
}
int hashtable_lookup_or_insert(HashTable *h,HashKey_t key,HashVal_t *valp,HashVal_t val) {
return _hashtable_lookup_or_insert(h,key,valp,val,1);
}
int hashtable_lookup(const HashTable *h,const HashKey_t key,HashVal_t *valp) {
uint32_t hash=h->hashFunc(h,key)%h->length;
HashNode *n;

View File

@ -22,8 +22,6 @@ typedef uint32_t (*HashFunc)(const HashTable *,const HashKey_t);
typedef int (*HashCmpFunc)(const HashTable *,const HashKey_t,const HashKey_t);
typedef void (*IteratorFunc)(const HashTable *,const HashKey_t,const HashVal_t,void *);
typedef void (*IteratorUpdateFunc)(const HashTable *,const HashKey_t,HashVal_t *,void *);
typedef void (*KeyDestroyFunc)(const HashTable *,HashKey_t);
typedef void (*ValDestroyFunc)(const HashTable *,HashVal_t);
typedef void (*ComputeFunc)(const HashTable *,const HashKey_t,HashVal_t *);
typedef void (*CollisionFunc)(const HashTable *,HashKey_t *,HashVal_t *,HashKey_t,HashVal_t);
@ -32,18 +30,11 @@ void hashtable_free(HashTable *h);
void hashtable_foreach(HashTable *h,IteratorFunc i,void *u);
void hashtable_foreach_update(HashTable *h,IteratorUpdateFunc i,void *u);
int hashtable_insert(HashTable *h,HashKey_t key,HashVal_t val);
int hashtable_update(HashTable *h,HashKey_t key,HashVal_t val);
int hashtable_lookup(const HashTable *h,const HashKey_t key,HashVal_t *valp);
int hashtable_lookup_or_insert(HashTable *h,HashKey_t key,HashVal_t *valp,HashVal_t val);
int hashtable_insert_or_update_computed(HashTable *h,HashKey_t key,ComputeFunc newFunc,ComputeFunc existsFunc);
int hashtable_delete(HashTable *h,const HashKey_t key);
int hashtable_remove(HashTable *h,const HashKey_t key,HashKey_t *keyRet,HashVal_t *valRet);
void *hashtable_set_user_data(HashTable *h,void *data);
void *hashtable_get_user_data(const HashTable *h);
KeyDestroyFunc hashtable_set_key_destroy_func(HashTable *,KeyDestroyFunc d);
ValDestroyFunc hashtable_set_value_destroy_func(HashTable *,ValDestroyFunc d);
uint32_t hashtable_get_count(const HashTable *h);
void hashtable_rehash(HashTable *h);
void hashtable_rehash_compute(HashTable *h,CollisionFunc cf);
#endif // __QUANTHASH_H__