4 __thread chashlistnode_t *c_table;
5 __thread chashlistnode_t *c_list;
6 __thread unsigned int c_size;
7 __thread unsigned INTPTR c_mask;
8 __thread unsigned int c_numelements;
9 __thread unsigned int c_threshold;
10 __thread double c_loadfactor;
11 __thread cliststruct_t *c_structs;
14 __thread rdchashlistnode_t *rd_c_table;
15 __thread rdchashlistnode_t *rd_c_list;
16 __thread unsigned int rd_c_size;
17 __thread unsigned INTPTR rd_c_mask;
18 __thread unsigned int rd_c_numelements;
19 __thread unsigned int rd_c_threshold;
20 __thread double rd_c_loadfactor;
21 __thread rdcliststruct_t *rd_c_structs;
23 void rd_t_chashCreate(unsigned int size, double loadfactor) {
25 chashlistnode_t *nodes;
28 // Allocate space for the hash table
29 rd_c_table = calloc(size, sizeof(rdchashlistnode_t));
30 rd_c_loadfactor = loadfactor;
32 rd_c_threshold=size*loadfactor;
33 rd_c_mask = (size << 4)-1;
34 rd_c_structs=calloc(1, sizeof(rdcliststruct_t));
35 rd_c_numelements = 0; // Initial number of elements in the hash
39 void rd_t_chashreset() {
40 rdchashlistnode_t *ptr = rd_c_table;
43 if (rd_c_numelements<(rd_c_size>>4)) {
44 rdchashlistnode_t *top=&ptr[rd_c_size];
45 rdchashlistnode_t *tmpptr=rd_c_list;
47 rdchashlistnode_t *next=tmpptr->lnext;
48 if (tmpptr>=ptr&&tmpptr<top) {
56 bzero(rd_c_table, sizeof(rdchashlistnode_t)*rd_c_size);
58 while(rd_c_structs->next!=NULL) {
59 rdcliststruct_t *next=rd_c_structs->next;
63 rd_c_structs->num = 0;
68 //Store objects and their pointers into hash
69 void rd_t_chashInsertOnce(void * key, unsigned int version) {
70 rdchashlistnode_t *ptr;
75 if(rd_c_numelements > (rd_c_threshold)) {
77 unsigned int newsize = rd_c_size << 1;
78 rd_t_chashResize(newsize);
81 ptr = &rd_c_table[(((unsigned INTPTR)key)&rd_c_mask)>>4];
89 } else { // Insert in the beginning of linked list
90 rdchashlistnode_t * node;
91 rdchashlistnode_t *search=ptr;
93 //make sure it isn't here
95 if(search->key == key) {
99 } while(search != NULL);
102 if (rd_c_structs->num<NUMCLIST) {
103 node=&rd_c_structs->array[rd_c_structs->num];
107 rdcliststruct_t *tcl=calloc(1,sizeof(rdcliststruct_t));
108 tcl->next=rd_c_structs;
114 node->version = version;
115 node->next = ptr->next;
117 node->lnext=rd_c_list;
122 unsigned int rd_t_chashResize(unsigned int newsize) {
123 rdchashlistnode_t *node, *ptr, *curr; // curr and next keep track of the current and the next chashlistnodes in a linked list
124 unsigned int oldsize;
125 int isfirst; // Keeps track of the first element in the chashlistnode_t for each bin in hashtable
126 unsigned int i,index;
133 if((node = calloc(newsize, sizeof(rdchashlistnode_t))) == NULL) {
134 printf("Calloc error %s %d\n", __FILE__, __LINE__);
138 rd_c_table = node; //Update the global hashtable upon resize()
140 rd_c_threshold = newsize * rd_c_loadfactor;
141 mask=rd_c_mask = (newsize << 4)-1;
143 for(i = 0; i < oldsize; i++) { //Outer loop for each bin in hash table
146 do { //Inner loop to go through linked lists
148 rdchashlistnode_t *tmp,*next;
150 if ((key=curr->key) == 0) { //Exit inner loop if there the first element is 0
151 break; //key = val =0 for element if not present within the hash table
153 index = (((unsigned INTPTR)key) & mask) >>4;
156 // Insert into the new table
159 tmp->version = curr->version;
160 tmp->lnext=rd_c_list;
163 NOTE: Add this case if you change this...
164 This case currently never happens because of the way things rehash....
166 chashlistnode_t *newnode= calloc(1, sizeof(chashlistnode_t));
167 newnode->key = curr->key;
168 newnode->val = curr->val;
169 newnode->next = tmp->next;
173 curr->next=tmp->next;
175 curr->lnext=rd_c_list;
184 free(ptr); //Free the memory of the old hash table
188 //Delete the entire hash table
189 void rd_t_chashDelete() {
191 rdcliststruct_t *ptr=rd_c_structs;
193 rdcliststruct_t *next=ptr->next;
205 __thread dchashlistnode_t *dc_c_table;
206 __thread dchashlistnode_t *dc_c_list;
207 __thread unsigned int dc_c_size;
208 __thread unsigned INTPTR dc_c_mask;
209 __thread unsigned int dc_c_numelements;
210 __thread unsigned int dc_c_threshold;
211 __thread double dc_c_loadfactor;
212 __thread dcliststruct_t *dc_c_structs;
214 void dc_t_chashCreate(unsigned int size, double loadfactor) {
215 dchashlistnode_t *nodes;
218 // Allocate space for the hash table
220 dc_c_table = calloc(size, sizeof(dchashlistnode_t));
221 dc_c_loadfactor = loadfactor;
223 dc_c_threshold=size*loadfactor;
224 dc_c_mask = (size << 4)-1;
225 dc_c_structs=calloc(1, sizeof(dcliststruct_t));
226 dc_c_numelements = 0; // Initial number of elements in the hash
230 void dc_t_chashreset() {
231 dchashlistnode_t *ptr = dc_c_table;
234 if (dc_c_numelements<(dc_c_size>>4)) {
235 dchashlistnode_t *top=&ptr[dc_c_size];
236 dchashlistnode_t *tmpptr=dc_c_list;
237 while(tmpptr!=NULL) {
238 dchashlistnode_t *next=tmpptr->lnext;
239 if (tmpptr>=ptr&&tmpptr<top) {
247 bzero(dc_c_table, sizeof(dchashlistnode_t)*dc_c_size);
249 while(dc_c_structs->next!=NULL) {
250 dcliststruct_t *next=dc_c_structs->next;
254 dc_c_structs->num = 0;
255 dc_c_numelements = 0;
259 //Store objects and their pointers into hash
260 void dc_t_chashInsertOnce(void * key, void *val) {
261 dchashlistnode_t *ptr;
266 if(dc_c_numelements > (dc_c_threshold)) {
268 unsigned int newsize = dc_c_size << 1;
269 dc_t_chashResize(newsize);
272 ptr = &dc_c_table[(((unsigned INTPTR)key)&dc_c_mask)>>4];
277 ptr->lnext=dc_c_list;
280 } else { // Insert in the beginning of linked list
281 dchashlistnode_t * node;
282 dchashlistnode_t *search=ptr;
284 //make sure it isn't here
286 if(search->key == key) {
290 } while(search != NULL);
293 if (dc_c_structs->num<NUMCLIST) {
294 node=&dc_c_structs->array[dc_c_structs->num];
298 dcliststruct_t *tcl=calloc(1,sizeof(dcliststruct_t));
299 tcl->next=dc_c_structs;
306 node->next = ptr->next;
308 node->lnext=dc_c_list;
314 //Store objects and their pointers into hash
315 void dc_t_chashInsertOnceArray(void * key, unsigned int intkey, void *val) {
316 dchashlistnode_t *ptr;
321 if(dc_c_numelements > (dc_c_threshold)) {
323 unsigned int newsize = dc_c_size << 1;
324 dc_t_chashResize(newsize);
327 ptr = &dc_c_table[(((unsigned INTPTR)key^intkey)&dc_c_mask)>>4];
333 ptr->lnext=dc_c_list;
336 } else { // Insert in the beginning of linked list
337 dchashlistnode_t * node;
338 dchashlistnode_t *search=ptr;
340 //make sure it isn't here
342 if(search->key == key&&search->intkey==intkey) {
346 } while(search != NULL);
349 if (dc_c_structs->num<NUMCLIST) {
350 node=&dc_c_structs->array[dc_c_structs->num];
354 dcliststruct_t *tcl=calloc(1,sizeof(dcliststruct_t));
355 tcl->next=dc_c_structs;
361 node->intkey = intkey;
363 node->next = ptr->next;
365 node->lnext=dc_c_list;
371 unsigned int dc_t_chashResize(unsigned int newsize) {
372 dchashlistnode_t *node, *ptr, *curr; // curr and next keep track of the current and the next chashlistnodes in a linked list
373 unsigned int oldsize;
374 int isfirst; // Keeps track of the first element in the chashlistnode_t for each bin in hashtable
375 unsigned int i,index;
382 if((node = calloc(newsize, sizeof(dchashlistnode_t))) == NULL) {
383 printf("Calloc error %s %d\n", __FILE__, __LINE__);
387 dc_c_table = node; //Update the global hashtable upon resize()
389 dc_c_threshold = newsize * dc_c_loadfactor;
390 mask=dc_c_mask = (newsize << 4)-1;
392 for(i = 0; i < oldsize; i++) { //Outer loop for each bin in hash table
395 do { //Inner loop to go through linked lists
400 dchashlistnode_t *tmp,*next;
402 if ((key=curr->key) == 0) { //Exit inner loop if there the first element is 0
403 break; //key = val =0 for element if not present within the hash table
407 index = (((unsigned INTPTR)key^intkey) & mask) >>4;
409 index = (((unsigned INTPTR)key) & mask) >>4;
413 // Insert into the new table
417 tmp->intkey = intkey;
419 tmp->val = curr->val;
420 tmp->lnext=dc_c_list;
423 NOTE: Add this case if you change this...
424 This case currently never happens because of the way things rehash....
426 chashlistnode_t *newnode= calloc(1, sizeof(chashlistnode_t));
427 newnode->key = curr->key;
428 newnode->val = curr->val;
429 newnode->next = tmp->next;
433 curr->next=tmp->next;
435 curr->lnext=dc_c_list;
444 free(ptr); //Free the memory of the old hash table
448 //Delete the entire hash table
449 void dc_t_chashDelete() {
451 dcliststruct_t *ptr=dc_c_structs;
453 dcliststruct_t *next=ptr->next;
463 // Search for an address for a given oid
464 INLINE void * dc_t_chashSearch(void * key) {
465 //REMOVE HASH FUNCTION CALL TO MAKE SURE IT IS INLINED HERE
466 dchashlistnode_t *node = &dc_c_table[(((unsigned INTPTR)key) & dc_c_mask)>>4];
469 if(node->key == key) {
473 } while(node != NULL);
479 // Search for an address for a given oid
480 INLINE void * dc_t_chashSearchArray(void * key, unsigned int intkey) {
481 //REMOVE HASH FUNCTION CALL TO MAKE SURE IT IS INLINED HERE
482 dchashlistnode_t *node = &dc_c_table[(((unsigned INTPTR)key^intkey) & dc_c_mask)>>4];
485 if(node->key == key && node->intkey==intkey) {
489 } while(node != NULL);
497 void t_chashCreate(unsigned int size, double loadfactor) {
498 chashtable_t *ctable;
499 chashlistnode_t *nodes;
502 // Allocate space for the hash table
505 c_table = calloc(size, sizeof(chashlistnode_t));
506 c_loadfactor = loadfactor;
508 c_threshold=size*loadfactor;
509 c_mask = (size << 4)-1;
510 c_structs=calloc(1, sizeof(cliststruct_t));
511 c_numelements = 0; // Initial number of elements in the hash
515 void t_chashreset() {
516 chashlistnode_t *ptr = c_table;
519 if (c_numelements<(c_size>>4)) {
520 chashlistnode_t *top=&ptr[c_size];
521 chashlistnode_t *tmpptr=c_list;
522 while(tmpptr!=NULL) {
523 chashlistnode_t *next=tmpptr->lnext;
524 if (tmpptr>=ptr&&tmpptr<top) {
532 bzero(c_table, sizeof(chashlistnode_t)*c_size);
534 while(c_structs->next!=NULL) {
535 cliststruct_t *next=c_structs->next;
544 //Store objects and their pointers into hash
545 void t_chashInsert(void * key, void *val) {
546 chashlistnode_t *ptr;
549 if(c_numelements > (c_threshold)) {
551 unsigned int newsize = c_size << 1;
552 t_chashResize(newsize);
555 ptr = &c_table[(((unsigned INTPTR)key)&c_mask)>>4];
563 } else { // Insert in the beginning of linked list
564 chashlistnode_t * node;
565 if (c_structs->num<NUMCLIST) {
566 node=&c_structs->array[c_structs->num];
570 cliststruct_t *tcl=calloc(1,sizeof(cliststruct_t));
578 node->next = ptr->next;
585 // Search for an address for a given oid
586 INLINE void * t_chashSearch(void * key) {
587 //REMOVE HASH FUNCTION CALL TO MAKE SURE IT IS INLINED HERE
588 chashlistnode_t *node = &c_table[(((unsigned INTPTR)key) & c_mask)>>4];
591 if(node->key == key) {
595 } while(node != NULL);
600 unsigned int t_chashResize(unsigned int newsize) {
601 chashlistnode_t *node, *ptr, *curr; // curr and next keep track of the current and the next chashlistnodes in a linked list
602 unsigned int oldsize;
603 int isfirst; // Keeps track of the first element in the chashlistnode_t for each bin in hashtable
604 unsigned int i,index;
611 if((node = calloc(newsize, sizeof(chashlistnode_t))) == NULL) {
612 printf("Calloc error %s %d\n", __FILE__, __LINE__);
616 c_table = node; //Update the global hashtable upon resize()
618 c_threshold = newsize * c_loadfactor;
619 mask=c_mask = (newsize << 4)-1;
621 for(i = 0; i < oldsize; i++) { //Outer loop for each bin in hash table
624 do { //Inner loop to go through linked lists
626 chashlistnode_t *tmp,*next;
628 if ((key=curr->key) == 0) { //Exit inner loop if there the first element is 0
629 break; //key = val =0 for element if not present within the hash table
631 index = (((unsigned INTPTR)key) & mask) >>4;
634 // Insert into the new table
637 tmp->val = curr->val;
641 NOTE: Add this case if you change this...
642 This case currently never happens because of the way things rehash....
644 chashlistnode_t *newnode= calloc(1, sizeof(chashlistnode_t));
645 newnode->key = curr->key;
646 newnode->val = curr->val;
647 newnode->next = tmp->next;
651 curr->next=tmp->next;
662 free(ptr); //Free the memory of the old hash table
666 //Delete the entire hash table
667 void t_chashDelete() {
669 cliststruct_t *ptr=c_structs;
671 cliststruct_t *next=ptr->next;