5 __thread chashlistnode_t *c_table;
6 __thread chashlistnode_t *c_list;
7 __thread unsigned int c_size;
8 __thread unsigned INTPTR c_mask;
9 __thread unsigned int c_numelements;
10 __thread unsigned int c_threshold;
11 __thread double c_loadfactor;
12 __thread cliststruct_t *c_structs;
15 __thread rdchashlistnode_t *rd_c_table;
16 __thread rdchashlistnode_t *rd_c_list;
17 __thread unsigned int rd_c_size;
18 __thread unsigned INTPTR rd_c_mask;
19 __thread unsigned int rd_c_numelements;
20 __thread unsigned int rd_c_threshold;
21 __thread double rd_c_loadfactor;
22 __thread rdcliststruct_t *rd_c_structs;
24 void rd_t_chashCreate(unsigned int size, double loadfactor) {
26 chashlistnode_t *nodes;
29 // Allocate space for the hash table
30 rd_c_table = calloc(size, sizeof(rdchashlistnode_t));
31 rd_c_loadfactor = loadfactor;
33 rd_c_threshold=size*loadfactor;
34 rd_c_mask = (size << 4)-1;
35 rd_c_structs=calloc(1, sizeof(rdcliststruct_t));
36 rd_c_numelements = 0; // Initial number of elements in the hash
40 void rd_t_chashreset() {
41 rdchashlistnode_t *ptr = rd_c_table;
44 if (rd_c_numelements<(rd_c_size>>4)) {
45 rdchashlistnode_t *top=&ptr[rd_c_size];
46 rdchashlistnode_t *tmpptr=rd_c_list;
48 rdchashlistnode_t *next=tmpptr->lnext;
49 if (tmpptr>=ptr&&tmpptr<top) {
57 bzero(rd_c_table, sizeof(rdchashlistnode_t)*rd_c_size);
59 while(rd_c_structs->next!=NULL) {
60 rdcliststruct_t *next=rd_c_structs->next;
64 rd_c_structs->num = 0;
69 //Store objects and their pointers into hash
70 void rd_t_chashInsertOnce(void * key, unsigned int version) {
71 rdchashlistnode_t *ptr;
73 if (unlikely(key==NULL))
76 if(unlikely(rd_c_numelements > (rd_c_threshold))) {
78 unsigned int newsize = rd_c_size << 1;
79 rd_t_chashResize(newsize);
82 ptr = &rd_c_table[(((unsigned INTPTR)key)&rd_c_mask)>>4];
90 } else { // Insert in the beginning of linked list
91 rdchashlistnode_t * node;
92 rdchashlistnode_t *search=ptr;
94 //make sure it isn't here
96 if(search->key == key) {
100 } while(search != NULL);
103 if (rd_c_structs->num<NUMCLIST) {
104 node=&rd_c_structs->array[rd_c_structs->num];
108 rdcliststruct_t *tcl=calloc(1,sizeof(rdcliststruct_t));
109 tcl->next=rd_c_structs;
115 node->version = version;
116 node->next = ptr->next;
118 node->lnext=rd_c_list;
123 unsigned int rd_t_chashResize(unsigned int newsize) {
124 rdchashlistnode_t *node, *ptr, *curr; // curr and next keep track of the current and the next chashlistnodes in a linked list
125 unsigned int oldsize;
126 int isfirst; // Keeps track of the first element in the chashlistnode_t for each bin in hashtable
127 unsigned int i,index;
134 if((node = calloc(newsize, sizeof(rdchashlistnode_t))) == NULL) {
135 printf("Calloc error %s %d\n", __FILE__, __LINE__);
139 rd_c_table = node; //Update the global hashtable upon resize()
141 rd_c_threshold = newsize * rd_c_loadfactor;
142 mask=rd_c_mask = (newsize << 4)-1;
144 for(i = 0; i < oldsize; i++) { //Outer loop for each bin in hash table
147 do { //Inner loop to go through linked lists
149 rdchashlistnode_t *tmp,*next;
151 if ((key=curr->key) == 0) { //Exit inner loop if there the first element is 0
152 break; //key = val =0 for element if not present within the hash table
154 index = (((unsigned INTPTR)key) & mask) >>4;
157 // Insert into the new table
160 tmp->version = curr->version;
161 tmp->lnext=rd_c_list;
164 NOTE: Add this case if you change this...
165 This case currently never happens because of the way things rehash....
167 chashlistnode_t *newnode= calloc(1, sizeof(chashlistnode_t));
168 newnode->key = curr->key;
169 newnode->val = curr->val;
170 newnode->next = tmp->next;
174 curr->next=tmp->next;
176 curr->lnext=rd_c_list;
185 free(ptr); //Free the memory of the old hash table
189 //Delete the entire hash table
190 void rd_t_chashDelete() {
192 rdcliststruct_t *ptr=rd_c_structs;
194 rdcliststruct_t *next=ptr->next;
206 __thread dchashlistnode_t *dc_c_table;
207 __thread dchashlistnode_t *dc_c_list;
208 __thread unsigned int dc_c_size;
209 __thread unsigned INTPTR dc_c_mask;
210 __thread unsigned int dc_c_numelements;
211 __thread unsigned int dc_c_threshold;
212 __thread double dc_c_loadfactor;
213 __thread dcliststruct_t *dc_c_structs;
215 void dc_t_chashCreate(unsigned int size, double loadfactor) {
216 dchashlistnode_t *nodes;
219 // Allocate space for the hash table
221 dc_c_table = calloc(size, sizeof(dchashlistnode_t));
222 dc_c_loadfactor = loadfactor;
224 dc_c_threshold=size*loadfactor;
225 dc_c_mask = (size << 4)-1;
226 dc_c_structs=calloc(1, sizeof(dcliststruct_t));
227 dc_c_numelements = 0; // Initial number of elements in the hash
231 void dc_t_chashreset() {
232 dchashlistnode_t *ptr = dc_c_table;
235 if (dc_c_numelements<(dc_c_size>>4)) {
236 dchashlistnode_t *top=&ptr[dc_c_size];
237 dchashlistnode_t *tmpptr=dc_c_list;
238 while(tmpptr!=NULL) {
239 dchashlistnode_t *next=tmpptr->lnext;
240 if (tmpptr>=ptr&&tmpptr<top) {
248 bzero(dc_c_table, sizeof(dchashlistnode_t)*dc_c_size);
250 while(dc_c_structs->next!=NULL) {
251 dcliststruct_t *next=dc_c_structs->next;
255 dc_c_structs->num = 0;
256 dc_c_numelements = 0;
260 //Store objects and their pointers into hash
261 void dc_t_chashInsertOnce(void * key) {
262 dchashlistnode_t *ptr;
264 if (unlikely(key==NULL)) {
268 if(unlikely(dc_c_numelements > dc_c_threshold)) {
270 unsigned int newsize = dc_c_size << 1;
271 dc_t_chashResize(newsize);
273 ptr = &dc_c_table[(((unsigned INTPTR)key)&dc_c_mask)>>4];
274 if(likely(ptr->key==0)) {
276 #if defined(STMARRAY)&&!defined(DUALVIEW)
279 ptr->lnext=dc_c_list;
282 } else { // Insert in the beginning of linked list
283 dchashlistnode_t * node;
284 dchashlistnode_t *search=ptr;
286 //make sure it isn't here
288 if(search->key == key) {
292 } while(search != NULL);
295 if (likely(dc_c_structs->num<NUMCLIST)) {
296 node=&dc_c_structs->array[dc_c_structs->num];
300 dcliststruct_t *tcl=calloc(1,sizeof(dcliststruct_t));
301 tcl->next=dc_c_structs;
306 #if defined(STMARRAY)&&!defined(DUALVIEW)
310 node->next = ptr->next;
312 node->lnext=dc_c_list;
317 #if defined(STMARRAY)&&!defined(DUALVIEW)
318 //Store objects and their pointers into hash
319 void dc_t_chashInsertOnceArray(void * key, unsigned int intkey) {
320 dchashlistnode_t *ptr;
322 if (unlikely(key==NULL))
325 if(unlikely(dc_c_numelements > dc_c_threshold)) {
327 unsigned int newsize = dc_c_size << 1;
328 dc_t_chashResize(newsize);
331 ptr = &dc_c_table[(((unsigned INTPTR)key^(intkey<<4))&dc_c_mask)>>4];
336 ptr->lnext=dc_c_list;
339 } else { // Insert in the beginning of linked list
340 dchashlistnode_t * node;
341 dchashlistnode_t *search=ptr;
343 //make sure it isn't here
345 if(search->key == key&&search->intkey==intkey) {
349 } while(search != NULL);
352 if (likely(dc_c_structs->num<NUMCLIST)) {
353 node=&dc_c_structs->array[dc_c_structs->num];
357 dcliststruct_t *tcl=calloc(1,sizeof(dcliststruct_t));
358 tcl->next=dc_c_structs;
364 node->intkey = intkey;
365 node->next = ptr->next;
367 node->lnext=dc_c_list;
373 unsigned int dc_t_chashResize(unsigned int newsize) {
374 dchashlistnode_t *node, *ptr, *curr; // curr and next keep track of the current and the next chashlistnodes in a linked list
375 unsigned int oldsize;
376 int isfirst; // Keeps track of the first element in the chashlistnode_t for each bin in hashtable
377 unsigned int i,index;
384 if((node = calloc(newsize, sizeof(dchashlistnode_t))) == NULL) {
385 printf("Calloc error %s %d\n", __FILE__, __LINE__);
389 dc_c_table = node; //Update the global hashtable upon resize()
391 dc_c_threshold = newsize * dc_c_loadfactor;
392 mask=dc_c_mask = (newsize << 4)-1;
394 for(i = 0; i < oldsize; i++) { //Outer loop for each bin in hash table
397 do { //Inner loop to go through linked lists
399 #if defined(STMARRAY)&&!defined(DUALVIEW)
402 dchashlistnode_t *tmp,*next;
404 if ((key=curr->key) == 0) { //Exit inner loop if there the first element is 0
405 break; //key = val =0 for element if not present within the hash table
407 #if defined(STMARRAY)&&!defined(DUALVIEW)
409 index = (((unsigned INTPTR)key^(intkey<<4)) & mask) >>4;
411 index = (((unsigned INTPTR)key) & mask) >>4;
415 // Insert into the new table
418 #if defined(STMARRAY)&!defined(DUALVIEW)
419 tmp->intkey = intkey;
421 tmp->lnext=dc_c_list;
424 NOTE: Add this case if you change this...
425 This case currently never happens because of the way things rehash....
427 chashlistnode_t *newnode= calloc(1, sizeof(chashlistnode_t));
428 newnode->key = curr->key;
429 newnode->val = curr->val;
430 newnode->next = tmp->next;
434 curr->next=tmp->next;
436 curr->lnext=dc_c_list;
445 free(ptr); //Free the memory of the old hash table
449 //Delete the entire hash table
450 void dc_t_chashDelete() {
452 dcliststruct_t *ptr=dc_c_structs;
454 dcliststruct_t *next=ptr->next;
464 // Search for an address for a given oid
465 INLINE int dc_t_chashSearch(void * key) {
466 //REMOVE HASH FUNCTION CALL TO MAKE SURE IT IS INLINED HERE
467 dchashlistnode_t *node = &dc_c_table[(((unsigned INTPTR)key) & dc_c_mask)>>4];
470 if(node->key == key) {
474 } while(node != NULL);
479 #if defined(STMARRAY)&!defined(DUALVIEW)
480 // Search for an address for a given oid
481 INLINE int dc_t_chashSearchArray(void * key, unsigned int intkey) {
482 //REMOVE HASH FUNCTION CALL TO MAKE SURE IT IS INLINED HERE
483 dchashlistnode_t *node = &dc_c_table[(((unsigned INTPTR)key^intkey) & dc_c_mask)>>4];
486 if(node->key == key && node->intkey==intkey) {
490 } while(node != NULL);
498 void t_chashCreate(unsigned int size, double loadfactor) {
499 chashtable_t *ctable;
500 chashlistnode_t *nodes;
503 // Allocate space for the hash table
506 c_table = calloc(size, sizeof(chashlistnode_t));
507 c_loadfactor = loadfactor;
509 c_threshold=size*loadfactor;
511 c_mask = ((size << 4)-1)&~(15UL);
513 c_mask = ((size << 4)-1)&~15;
515 c_structs=calloc(1, sizeof(cliststruct_t));
516 c_numelements = 0; // Initial number of elements in the hash
520 void t_chashreset() {
521 chashlistnode_t *ptr = c_table;
524 if (c_numelements<(c_size>>4)) {
525 chashlistnode_t *top=&ptr[c_size];
526 chashlistnode_t *tmpptr=c_list;
527 while(tmpptr!=NULL) {
528 chashlistnode_t *next=tmpptr->lnext;
529 if (tmpptr>=ptr&&tmpptr<top) {
537 bzero(c_table, sizeof(chashlistnode_t)*c_size);
539 while(c_structs->next!=NULL) {
540 cliststruct_t *next=c_structs->next;
549 //Store objects and their pointers into hash
550 void t_chashInsert(void * key, void *val) {
551 chashlistnode_t *ptr;
554 if(c_numelements > (c_threshold)) {
556 unsigned int newsize = c_size << 1;
557 t_chashResize(newsize);
560 ptr = &c_table[(((unsigned INTPTR)key)&c_mask)>>4];
568 } else { // Insert in the beginning of linked list
569 chashlistnode_t * node;
570 if (c_structs->num<NUMCLIST) {
571 node=&c_structs->array[c_structs->num];
575 cliststruct_t *tcl=calloc(1,sizeof(cliststruct_t));
583 node->next = ptr->next;
590 // Search for an address for a given oid
591 INLINE void * t_chashSearch(void * key) {
592 //REMOVE HASH FUNCTION CALL TO MAKE SURE IT IS INLINED HERE
593 chashlistnode_t *node = &c_table[(((unsigned INTPTR)key) & c_mask)>>4];
596 if(node->key == key) {
600 } while(node != NULL);
605 unsigned int t_chashResize(unsigned int newsize) {
606 chashlistnode_t *node, *ptr, *curr; // curr and next keep track of the current and the next chashlistnodes in a linked list
607 unsigned int oldsize;
608 int isfirst; // Keeps track of the first element in the chashlistnode_t for each bin in hashtable
609 unsigned int i,index;
616 if((node = calloc(newsize, sizeof(chashlistnode_t))) == NULL) {
617 printf("Calloc error %s %d\n", __FILE__, __LINE__);
621 c_table = node; //Update the global hashtable upon resize()
623 c_threshold = newsize * c_loadfactor;
624 mask=c_mask = (newsize << 4)-1;
626 for(i = 0; i < oldsize; i++) { //Outer loop for each bin in hash table
629 do { //Inner loop to go through linked lists
631 chashlistnode_t *tmp,*next;
633 if ((key=curr->key) == 0) { //Exit inner loop if there the first element is 0
634 break; //key = val =0 for element if not present within the hash table
636 index = (((unsigned INTPTR)key) & mask) >>4;
639 // Insert into the new table
642 tmp->val = curr->val;
646 NOTE: Add this case if you change this...
647 This case currently never happens because of the way things rehash....
649 chashlistnode_t *newnode= calloc(1, sizeof(chashlistnode_t));
650 newnode->key = curr->key;
651 newnode->val = curr->val;
652 newnode->next = tmp->next;
656 curr->next=tmp->next;
667 free(ptr); //Free the memory of the old hash table
671 //Delete the entire hash table
672 void t_chashDelete() {
674 cliststruct_t *ptr=c_structs;
676 cliststruct_t *next=ptr->next;