33 for(i=0;i<hmap->
length;i++)
35 for(
this=hmap->
elems[i];
this;
this=next)
38 index=(hmap->
hash)(this->key)%(2*hmap->
length);
39 this->next=
new[index];
53 int(*equals)(
void*,
void*))
63 if(factor<0.1) hmap->
factor=0.1;
84 else hmap->
hash=*hash;
103 if(factor<0.1) result=1;
114 for(i=0;i<hmap->
length;i++)
116 for(p=hmap->
elems[i];p;)
131 int h,stop,error=0,result=0;
137 for(aux=hmap->
elems[h],stop=0;aux&&!stop;aux=aux->
next)
141 if(replace) aux->
value=value;
172 for(aux=hmap->
elems[index],last=&(hmap->
elems[index]);
178 if(del) del(aux->
key);
179 if(*value) *value=aux->
value;
185 if(value) *value=NULL;
200 if(aux) *value=aux->
value;
225 for(i=0,error=0;i<hmap->
length&&!error;i++)
226 for(aux=hmap->
elems[i];aux&&!error;aux=aux->
next)
246 for(i=0,error=0;i<hmap->
length&&!error;i++)
247 for(aux=hmap->
elems[i];aux&&!error;aux=aux->
next)
int hashSetEquals(HashMap hmap, int(*equals)(void *, void *))
Sets the comparison function of a hash table.
int hashInsert(HashMap hmap, void *key, void *value, int replace)
Associates a value to a key in a hash table.
Implementation of a hash table.
Iterator hashKeys(HashMap hmap)
Creates an iterator from the keys of a hash table.
void * value
Node's value.
int hashGet(HashMap hmap, void *key, void **value)
Provides the mapping for a key from a hash table.
Iterator hashValues(HashMap hmap)
Creates an iterator from the values of a hash table.
struct sHashNode * next
Next node.
void itDelete(Iterator it)
Deletes an iterator.
HashNode * elems
Buckets of this hash table.
static int reHash(HashMap hmap)
Resizes a hash table.
int length
Number of buckets of this hash table.
int itAdd(Iterator it, void *val)
Adds an element to an iterator.
int(* hash)(void *)
Hash function of this hash table.
HashMap newHash(int size, float factor, int(*hash)(void *), int(*equals)(void *, void *))
Creates a hash table.
int hashSetHash(HashMap hmap, int(*hash)(void *))
Sets the hash function of a hash table.
void hashDelete(HashMap hmap)
Deletes a hash table.
int size
Number of elements of this hash table.
Hash table node structure.
int hashSetFactor(HashMap hmap, int factor)
Sets the load factor of a hash table.
int hashSize(HashMap hmap)
Returns the number of elements present in a hash table.
int hashRemove(HashMap hmap, void *key, void **value, void(*del)(void *))
Removes the mapping for a key from a hash table.
Iterator newIt(int size)
Creates an iterator.
int(* equals)(void *, void *)
Comparison function of this hash table.