27#define BUCKET(table,i) table->buckets[i]
28#define HASHSIZE(table) table->size
36 table->last_node = BUCKET(table,mhash(table,key));
37 while ( table->last_node != NULL ) {
38 if( table->last_node->value==key)
return table->last_node;
39 table->last_node = table->last_node->next;
43__ptr_t get_next_object(
hashtable table,ulong key)
45 if(table->last_node==NULL)
47 table->last_node = table->last_node->next;
48 while ( table->last_node != NULL ) {
49 if( table->last_node->value==key)
return table->last_node->obj;
50 table->last_node = table->last_node->next;
61 int c=mhash(table,key);
67 BUCKET(table,c)=b->next;
80__ptr_t replace_object(
hashtable table,ulong key,__ptr_t newobj)
85 if(b==NULL)
return NULL;
93__ptr_t get_object(
hashtable table,ulong key){
114 for(i=0;i<hashsize;++i) BUCKET(
new,i) = NULL;
119static int mhash(
hashtable table,ulong key)
121 return (
int)(key%HASHSIZE(table));
125int insere(
hashtable table,ulong key,__ptr_t obj)
130 ind=mhash(table,key);
132 new->next = BUCKET(table,ind);
135 BUCKET(table,ind)=
new;
145 if (table==NULL)
return;
146 for(i=0;i<HASHSIZE(table);++i) {
154 free(table->buckets);
161void init_hash_traversal(
hashtable table) {
162 table->last_bucket=0;
163 table->last_node=NULL;
171 if( table->last_bucket>=HASHSIZE(table))
174 if( table->last_node==NULL ) {
177 while ( table->last_node == NULL && table->last_bucket+1<HASHSIZE(table)) {
178 ++table->last_bucket;
179 table->last_node = BUCKET(table,table->last_bucket);
181 if (table->last_node==NULL)
183 return table->last_node->obj;
186 table->last_node=table->last_node->next;
187 if (table->last_node==NULL)
return next_hash_object(table);
188 return table->last_node->obj;
197 if( table->last_bucket>=HASHSIZE(table))
200 if( table->last_node==NULL ) {
203 while ( table->last_node == NULL && table->last_bucket+1<HASHSIZE(table)) {
204 ++table->last_bucket;
205 table->last_node = BUCKET(table,table->last_bucket);
207 if (table->last_node==NULL)
209 return table->last_node;
212 table->last_node=table->last_node->next;
213 if (table->last_node==NULL)
return next_hashnode(table);
214 return table->last_node;