36 #if _MSC_VER >= 1600 && defined(__cplusplus) 37 #define DECLTYPE(x) (decltype(x)) 43 #define DECLTYPE(x) (__typeof(x)) 47 #define DECLTYPE_ASSIGN(dst,src) \ 49 char **_da_dst = (char**)(&(dst)); \ 50 *_da_dst = (char*)(src); \ 53 #define DECLTYPE_ASSIGN(dst,src) \ 55 (dst) = DECLTYPE(dst)(src); \ 61 typedef unsigned int uint32_t;
62 typedef unsigned char uint8_t;
67 #define UTHASH_VERSION 1.9.6 70 #define uthash_fatal(msg) exit(-1) 73 #define uthash_malloc(sz) malloc(sz) 76 #define uthash_free(ptr,sz) free(ptr) 79 #ifndef uthash_noexpand_fyi 80 #define uthash_noexpand_fyi(tbl) 82 #ifndef uthash_expand_fyi 83 #define uthash_expand_fyi(tbl) 87 #define HASH_INITIAL_NUM_BUCKETS 32 88 #define HASH_INITIAL_NUM_BUCKETS_LOG2 5 89 #define HASH_BKT_CAPACITY_THRESH 10 92 #define ELMT_FROM_HH(tbl,hhp) ((void*)(((char*)(hhp)) - ((tbl)->hho))) 94 #define HASH_FIND(hh,head,keyptr,keylen,out) \ 96 unsigned _hf_bkt,_hf_hashv; \ 99 HASH_FCN(keyptr,keylen, (head)->hh.tbl->num_buckets, _hf_hashv, _hf_bkt); \ 100 if (HASH_BLOOM_TEST((head)->hh.tbl, _hf_hashv)) { \ 101 HASH_FIND_IN_BKT((head)->hh.tbl, hh, (head)->hh.tbl->buckets[ _hf_bkt ], \ 102 keyptr,keylen,out); \ 108 #define HASH_BLOOM_BITLEN (1ULL << HASH_BLOOM) 109 #define HASH_BLOOM_BYTELEN (HASH_BLOOM_BITLEN/8) + ((HASH_BLOOM_BITLEN%8) ? 1:0) 110 #define HASH_BLOOM_MAKE(tbl) \ 112 (tbl)->bloom_nbits = HASH_BLOOM; \ 113 (tbl)->bloom_bv = (uint8_t*)uthash_malloc(HASH_BLOOM_BYTELEN); \ 114 if (!((tbl)->bloom_bv)) { uthash_fatal( "out of memory"); } \ 115 memset((tbl)->bloom_bv, 0, HASH_BLOOM_BYTELEN); \ 116 (tbl)->bloom_sig = HASH_BLOOM_SIGNATURE; \ 119 #define HASH_BLOOM_FREE(tbl) \ 121 uthash_free((tbl)->bloom_bv, HASH_BLOOM_BYTELEN); \ 124 #define HASH_BLOOM_BITSET(bv,idx) (bv[(idx)/8] |= (1U << ((idx)%8))) 125 #define HASH_BLOOM_BITTEST(bv,idx) (bv[(idx)/8] & (1U << ((idx)%8))) 127 #define HASH_BLOOM_ADD(tbl,hashv) \ 128 HASH_BLOOM_BITSET((tbl)->bloom_bv, (hashv & (uint32_t)((1ULL << (tbl)->bloom_nbits) - 1))) 130 #define HASH_BLOOM_TEST(tbl,hashv) \ 131 HASH_BLOOM_BITTEST((tbl)->bloom_bv, (hashv & (uint32_t)((1ULL << (tbl)->bloom_nbits) - 1))) 134 #define HASH_BLOOM_MAKE(tbl) 135 #define HASH_BLOOM_FREE(tbl) 136 #define HASH_BLOOM_ADD(tbl,hashv) 137 #define HASH_BLOOM_TEST(tbl,hashv) (1) 140 #define HASH_MAKE_TABLE(hh,head) \ 142 (head)->hh.tbl = (UT_hash_table*)uthash_malloc( \ 143 sizeof(UT_hash_table)); \ 144 if (!((head)->hh.tbl)) { uthash_fatal( "out of memory"); } \ 145 memset((head)->hh.tbl, 0, sizeof(UT_hash_table)); \ 146 (head)->hh.tbl->tail = &((head)->hh); \ 147 (head)->hh.tbl->num_buckets = HASH_INITIAL_NUM_BUCKETS; \ 148 (head)->hh.tbl->log2_num_buckets = HASH_INITIAL_NUM_BUCKETS_LOG2; \ 149 (head)->hh.tbl->hho = (char*)(&(head)->hh) - (char*)(head); \ 150 (head)->hh.tbl->buckets = (UT_hash_bucket*)uthash_malloc( \ 151 HASH_INITIAL_NUM_BUCKETS*sizeof(struct UT_hash_bucket)); \ 152 if (! (head)->hh.tbl->buckets) { uthash_fatal( "out of memory"); } \ 153 memset((head)->hh.tbl->buckets, 0, \ 154 HASH_INITIAL_NUM_BUCKETS*sizeof(struct UT_hash_bucket)); \ 155 HASH_BLOOM_MAKE((head)->hh.tbl); \ 156 (head)->hh.tbl->signature = HASH_SIGNATURE; \ 159 #define HASH_ADD(hh,head,fieldname,keylen_in,add) \ 160 HASH_ADD_KEYPTR(hh,head,&((add)->fieldname),keylen_in,add) 162 #define HASH_ADD_KEYPTR(hh,head,keyptr,keylen_in,add) \ 165 (add)->hh.next = NULL; \ 166 (add)->hh.key = (char*)keyptr; \ 167 (add)->hh.keylen = (unsigned)keylen_in; \ 170 (head)->hh.prev = NULL; \ 171 HASH_MAKE_TABLE(hh,head); \ 173 (head)->hh.tbl->tail->next = (add); \ 174 (add)->hh.prev = ELMT_FROM_HH((head)->hh.tbl, (head)->hh.tbl->tail); \ 175 (head)->hh.tbl->tail = &((add)->hh); \ 177 (head)->hh.tbl->num_items++; \ 178 (add)->hh.tbl = (head)->hh.tbl; \ 179 HASH_FCN(keyptr,keylen_in, (head)->hh.tbl->num_buckets, \ 180 (add)->hh.hashv, _ha_bkt); \ 181 HASH_ADD_TO_BKT((head)->hh.tbl->buckets[_ha_bkt],&(add)->hh); \ 182 HASH_BLOOM_ADD((head)->hh.tbl,(add)->hh.hashv); \ 183 HASH_EMIT_KEY(hh,head,keyptr,keylen_in); \ 184 HASH_FSCK(hh,head); \ 187 #define HASH_TO_BKT( hashv, num_bkts, bkt ) \ 189 bkt = ((hashv) & ((num_bkts) - 1)); \ 204 #define HASH_DELETE(hh,head,delptr) \ 207 struct UT_hash_handle *_hd_hh_del; \ 208 if ( ((delptr)->hh.prev == NULL) && ((delptr)->hh.next == NULL) ) { \ 209 uthash_free((head)->hh.tbl->buckets, \ 210 (head)->hh.tbl->num_buckets*sizeof(struct UT_hash_bucket) ); \ 211 HASH_BLOOM_FREE((head)->hh.tbl); \ 212 uthash_free((head)->hh.tbl, sizeof(UT_hash_table)); \ 215 _hd_hh_del = &((delptr)->hh); \ 216 if ((delptr) == ELMT_FROM_HH((head)->hh.tbl,(head)->hh.tbl->tail)) { \ 217 (head)->hh.tbl->tail = \ 218 (UT_hash_handle*)((char*)((delptr)->hh.prev) + \ 219 (head)->hh.tbl->hho); \ 221 if ((delptr)->hh.prev) { \ 222 ((UT_hash_handle*)((char*)((delptr)->hh.prev) + \ 223 (head)->hh.tbl->hho))->next = (delptr)->hh.next; \ 225 DECLTYPE_ASSIGN(head,(delptr)->hh.next); \ 227 if (_hd_hh_del->next) { \ 228 ((UT_hash_handle*)((char*)_hd_hh_del->next + \ 229 (head)->hh.tbl->hho))->prev = \ 232 HASH_TO_BKT( _hd_hh_del->hashv, (head)->hh.tbl->num_buckets, _hd_bkt); \ 233 HASH_DEL_IN_BKT(hh,(head)->hh.tbl->buckets[_hd_bkt], _hd_hh_del); \ 234 (head)->hh.tbl->num_items--; \ 236 HASH_FSCK(hh,head); \ 241 #define HASH_FIND_STR(head,findstr,out) \ 242 HASH_FIND(hh,head,findstr,strlen(findstr),out) 243 #define HASH_ADD_STR(head,strfield,add) \ 244 HASH_ADD(hh,head,strfield,strlen(add->strfield),add) 245 #define HASH_FIND_INT(head,findint,out) \ 246 HASH_FIND(hh,head,findint,sizeof(int),out) 247 #define HASH_ADD_INT(head,intfield,add) \ 248 HASH_ADD(hh,head,intfield,sizeof(int),add) 249 #define HASH_FIND_PTR(head,findptr,out) \ 250 HASH_FIND(hh,head,findptr,sizeof(void *),out) 251 #define HASH_ADD_PTR(head,ptrfield,add) \ 252 HASH_ADD(hh,head,ptrfield,sizeof(void *),add) 253 #define HASH_DEL(head,delptr) \ 254 HASH_DELETE(hh,head,delptr) 260 #define HASH_OOPS(...) do { fprintf(stderr,__VA_ARGS__); exit(-1); } while (0) 261 #define HASH_FSCK(hh,head) \ 264 unsigned _count, _bkt_count; \ 266 struct UT_hash_handle *_thh; \ 269 for( _bkt_i = 0; _bkt_i < (head)->hh.tbl->num_buckets; _bkt_i++) { \ 271 _thh = (head)->hh.tbl->buckets[_bkt_i].hh_head; \ 274 if (_prev != (char*)(_thh->hh_prev)) { \ 275 HASH_OOPS("invalid hh_prev %p, actual %p\n", \ 276 _thh->hh_prev, _prev ); \ 279 _prev = (char*)(_thh); \ 280 _thh = _thh->hh_next; \ 282 _count += _bkt_count; \ 283 if ((head)->hh.tbl->buckets[_bkt_i].count != _bkt_count) { \ 284 HASH_OOPS("invalid bucket count %d, actual %d\n", \ 285 (head)->hh.tbl->buckets[_bkt_i].count, _bkt_count); \ 288 if (_count != (head)->hh.tbl->num_items) { \ 289 HASH_OOPS("invalid hh item count %d, actual %d\n", \ 290 (head)->hh.tbl->num_items, _count ); \ 295 _thh = &(head)->hh; \ 298 if (_prev !=(char*)(_thh->prev)) { \ 299 HASH_OOPS("invalid prev %p, actual %p\n", \ 300 _thh->prev, _prev ); \ 302 _prev = (char*)ELMT_FROM_HH((head)->hh.tbl, _thh); \ 303 _thh = ( _thh->next ? (UT_hash_handle*)((char*)(_thh->next) + \ 304 (head)->hh.tbl->hho) : NULL ); \ 306 if (_count != (head)->hh.tbl->num_items) { \ 307 HASH_OOPS("invalid app item count %d, actual %d\n", \ 308 (head)->hh.tbl->num_items, _count ); \ 313 #define HASH_FSCK(hh,head) 319 #ifdef HASH_EMIT_KEYS 320 #define HASH_EMIT_KEY(hh,head,keyptr,fieldlen) \ 322 unsigned _klen = fieldlen; \ 323 write(HASH_EMIT_KEYS, &_klen, sizeof(_klen)); \ 324 write(HASH_EMIT_KEYS, keyptr, fieldlen); \ 327 #define HASH_EMIT_KEY(hh,head,keyptr,fieldlen) 332 #define HASH_FCN HASH_FUNCTION 334 #define HASH_FCN HASH_JEN 338 #define HASH_BER(key,keylen,num_bkts,hashv,bkt) \ 340 unsigned _hb_keylen=keylen; \ 341 char *_hb_key=(char*)(key); \ 343 while (_hb_keylen--) { (hashv) = ((hashv) * 33) + *_hb_key++; } \ 344 bkt = (hashv) & (num_bkts-1); \ 350 #define HASH_SAX(key,keylen,num_bkts,hashv,bkt) \ 353 char *_hs_key=(char*)(key); \ 355 for(_sx_i=0; _sx_i < keylen; _sx_i++) \ 356 hashv ^= (hashv << 5) + (hashv >> 2) + _hs_key[_sx_i]; \ 357 bkt = hashv & (num_bkts-1); \ 360 #define HASH_FNV(key,keylen,num_bkts,hashv,bkt) \ 363 char *_hf_key=(char*)(key); \ 364 hashv = 2166136261UL; \ 365 for(_fn_i=0; _fn_i < keylen; _fn_i++) \ 366 hashv = (hashv * 16777619) ^ _hf_key[_fn_i]; \ 367 bkt = hashv & (num_bkts-1); \ 370 #define HASH_OAT(key,keylen,num_bkts,hashv,bkt) \ 373 char *_ho_key=(char*)(key); \ 375 for(_ho_i=0; _ho_i < keylen; _ho_i++) { \ 376 hashv += _ho_key[_ho_i]; \ 377 hashv += (hashv << 10); \ 378 hashv ^= (hashv >> 6); \ 380 hashv += (hashv << 3); \ 381 hashv ^= (hashv >> 11); \ 382 hashv += (hashv << 15); \ 383 bkt = hashv & (num_bkts-1); \ 386 #define HASH_JEN_MIX(a,b,c) \ 388 a -= b; a -= c; a ^= ( c >> 13 ); \ 389 b -= c; b -= a; b ^= ( a << 8 ); \ 390 c -= a; c -= b; c ^= ( b >> 13 ); \ 391 a -= b; a -= c; a ^= ( c >> 12 ); \ 392 b -= c; b -= a; b ^= ( a << 16 ); \ 393 c -= a; c -= b; c ^= ( b >> 5 ); \ 394 a -= b; a -= c; a ^= ( c >> 3 ); \ 395 b -= c; b -= a; b ^= ( a << 10 ); \ 396 c -= a; c -= b; c ^= ( b >> 15 ); \ 399 #define HASH_JEN(key,keylen,num_bkts,hashv,bkt) \ 401 unsigned _hj_i,_hj_j,_hj_k; \ 402 char *_hj_key=(char*)(key); \ 403 hashv = 0xfeedbeef; \ 404 _hj_i = _hj_j = 0x9e3779b9; \ 405 _hj_k = (unsigned)keylen; \ 406 while (_hj_k >= 12) { \ 407 _hj_i += (_hj_key[0] + ( (unsigned)_hj_key[1] << 8 ) \ 408 + ( (unsigned)_hj_key[2] << 16 ) \ 409 + ( (unsigned)_hj_key[3] << 24 ) ); \ 410 _hj_j += (_hj_key[4] + ( (unsigned)_hj_key[5] << 8 ) \ 411 + ( (unsigned)_hj_key[6] << 16 ) \ 412 + ( (unsigned)_hj_key[7] << 24 ) ); \ 413 hashv += (_hj_key[8] + ( (unsigned)_hj_key[9] << 8 ) \ 414 + ( (unsigned)_hj_key[10] << 16 ) \ 415 + ( (unsigned)_hj_key[11] << 24 ) ); \ 417 HASH_JEN_MIX(_hj_i, _hj_j, hashv); \ 424 case 11: hashv += ( (unsigned)_hj_key[10] << 24 ); \ 425 case 10: hashv += ( (unsigned)_hj_key[9] << 16 ); \ 426 case 9: hashv += ( (unsigned)_hj_key[8] << 8 ); \ 427 case 8: _hj_j += ( (unsigned)_hj_key[7] << 24 ); \ 428 case 7: _hj_j += ( (unsigned)_hj_key[6] << 16 ); \ 429 case 6: _hj_j += ( (unsigned)_hj_key[5] << 8 ); \ 430 case 5: _hj_j += _hj_key[4]; \ 431 case 4: _hj_i += ( (unsigned)_hj_key[3] << 24 ); \ 432 case 3: _hj_i += ( (unsigned)_hj_key[2] << 16 ); \ 433 case 2: _hj_i += ( (unsigned)_hj_key[1] << 8 ); \ 434 case 1: _hj_i += _hj_key[0]; \ 436 HASH_JEN_MIX(_hj_i, _hj_j, hashv); \ 437 bkt = hashv & (num_bkts-1); \ 442 #if (defined(__GNUC__) && defined(__i386__)) || defined(__WATCOMC__) \ 443 || defined(_MSC_VER) || defined (__BORLANDC__) || defined (__TURBOC__) 444 #define get16bits(d) (*((const uint16_t *) (d))) 447 #if !defined (get16bits) 448 #define get16bits(d) ((((uint32_t)(((const uint8_t *)(d))[1])) << 8) \ 449 +(uint32_t)(((const uint8_t *)(d))[0]) ) 451 #define HASH_SFH(key,keylen,num_bkts,hashv,bkt) \ 453 char *_sfh_key=(char*)(key); \ 454 uint32_t _sfh_tmp, _sfh_len = keylen; \ 456 int _sfh_rem = _sfh_len & 3; \ 458 hashv = 0xcafebabe; \ 461 for (;_sfh_len > 0; _sfh_len--) { \ 462 hashv += get16bits (_sfh_key); \ 463 _sfh_tmp = (get16bits (_sfh_key+2) << 11) ^ hashv; \ 464 hashv = (hashv << 16) ^ _sfh_tmp; \ 465 _sfh_key += 2*sizeof (uint16_t); \ 466 hashv += hashv >> 11; \ 470 switch (_sfh_rem) { \ 471 case 3: hashv += get16bits (_sfh_key); \ 472 hashv ^= hashv << 16; \ 473 hashv ^= _sfh_key[sizeof (uint16_t)] << 18; \ 474 hashv += hashv >> 11; \ 476 case 2: hashv += get16bits (_sfh_key); \ 477 hashv ^= hashv << 11; \ 478 hashv += hashv >> 17; \ 480 case 1: hashv += *_sfh_key; \ 481 hashv ^= hashv << 10; \ 482 hashv += hashv >> 1; \ 486 hashv ^= hashv << 3; \ 487 hashv += hashv >> 5; \ 488 hashv ^= hashv << 4; \ 489 hashv += hashv >> 17; \ 490 hashv ^= hashv << 25; \ 491 hashv += hashv >> 6; \ 492 bkt = hashv & (num_bkts-1); \ 495 #ifdef HASH_USING_NO_STRICT_ALIASING 505 #if (defined(__i386__) || defined(__x86_64__)) 506 #define MUR_GETBLOCK(p,i) p[i] 508 #define MUR_PLUS0_ALIGNED(p) (((unsigned long)p & 0x3) == 0) 509 #define MUR_PLUS1_ALIGNED(p) (((unsigned long)p & 0x3) == 1) 510 #define MUR_PLUS2_ALIGNED(p) (((unsigned long)p & 0x3) == 2) 511 #define MUR_PLUS3_ALIGNED(p) (((unsigned long)p & 0x3) == 3) 512 #define WP(p) ((uint32_t*)((unsigned long)(p) & ~3UL)) 513 #if (defined(__BIG_ENDIAN__) || defined(SPARC) || defined(__ppc__) || defined(__ppc64__)) 514 #define MUR_THREE_ONE(p) ((((*WP(p))&0x00ffffff) << 8) | (((*(WP(p)+1))&0xff000000) >> 24)) 515 #define MUR_TWO_TWO(p) ((((*WP(p))&0x0000ffff) <<16) | (((*(WP(p)+1))&0xffff0000) >> 16)) 516 #define MUR_ONE_THREE(p) ((((*WP(p))&0x000000ff) <<24) | (((*(WP(p)+1))&0xffffff00) >> 8)) 518 #define MUR_THREE_ONE(p) ((((*WP(p))&0xffffff00) >> 8) | (((*(WP(p)+1))&0x000000ff) << 24)) 519 #define MUR_TWO_TWO(p) ((((*WP(p))&0xffff0000) >>16) | (((*(WP(p)+1))&0x0000ffff) << 16)) 520 #define MUR_ONE_THREE(p) ((((*WP(p))&0xff000000) >>24) | (((*(WP(p)+1))&0x00ffffff) << 8)) 522 #define MUR_GETBLOCK(p,i) (MUR_PLUS0_ALIGNED(p) ? ((p)[i]) : \ 523 (MUR_PLUS1_ALIGNED(p) ? MUR_THREE_ONE(p) : \ 524 (MUR_PLUS2_ALIGNED(p) ? MUR_TWO_TWO(p) : \ 527 #define MUR_ROTL32(x,r) (((x) << (r)) | ((x) >> (32 - (r)))) 528 #define MUR_FMIX(_h) \ 537 #define HASH_MUR(key,keylen,num_bkts,hashv,bkt) \ 539 const uint8_t *_mur_data = (const uint8_t*)(key); \ 540 const int _mur_nblocks = (keylen) / 4; \ 541 uint32_t _mur_h1 = 0xf88D5353; \ 542 uint32_t _mur_c1 = 0xcc9e2d51; \ 543 uint32_t _mur_c2 = 0x1b873593; \ 544 const uint32_t *_mur_blocks = (const uint32_t*)(_mur_data+_mur_nblocks*4); \ 546 for(_mur_i = -_mur_nblocks; _mur_i; _mur_i++) { \ 547 uint32_t _mur_k1 = MUR_GETBLOCK(_mur_blocks,_mur_i); \ 548 _mur_k1 *= _mur_c1; \ 549 _mur_k1 = MUR_ROTL32(_mur_k1,15); \ 550 _mur_k1 *= _mur_c2; \ 552 _mur_h1 ^= _mur_k1; \ 553 _mur_h1 = MUR_ROTL32(_mur_h1,13); \ 554 _mur_h1 = _mur_h1*5+0xe6546b64; \ 556 const uint8_t *_mur_tail = (const uint8_t*)(_mur_data + _mur_nblocks*4); \ 557 uint32_t _mur_k1=0; \ 558 switch((keylen) & 3) { \ 559 case 3: _mur_k1 ^= _mur_tail[2] << 16; \ 560 case 2: _mur_k1 ^= _mur_tail[1] << 8; \ 561 case 1: _mur_k1 ^= _mur_tail[0]; \ 562 _mur_k1 *= _mur_c1; \ 563 _mur_k1 = MUR_ROTL32(_mur_k1,15); \ 564 _mur_k1 *= _mur_c2; \ 565 _mur_h1 ^= _mur_k1; \ 567 _mur_h1 ^= (keylen); \ 570 bkt = hashv & (num_bkts-1); \ 575 #define HASH_KEYCMP(a,b,len) memcmp(a,b,len) 578 #define HASH_FIND_IN_BKT(tbl,hh,head,keyptr,keylen_in,out) \ 580 if (head.hh_head) DECLTYPE_ASSIGN(out,ELMT_FROM_HH(tbl,head.hh_head)); \ 583 if ((out)->hh.keylen == keylen_in) { \ 584 if ((HASH_KEYCMP((out)->hh.key,keyptr,keylen_in)) == 0) break; \ 586 if ((out)->hh.hh_next) DECLTYPE_ASSIGN(out,ELMT_FROM_HH(tbl,(out)->hh.hh_next)); \ 592 #define HASH_ADD_TO_BKT(head,addhh) \ 595 (addhh)->hh_next = head.hh_head; \ 596 (addhh)->hh_prev = NULL; \ 597 if (head.hh_head) { (head).hh_head->hh_prev = (addhh); } \ 598 (head).hh_head=addhh; \ 599 if (head.count >= ((head.expand_mult+1) * HASH_BKT_CAPACITY_THRESH) \ 600 && (addhh)->tbl->noexpand != 1) { \ 601 HASH_EXPAND_BUCKETS((addhh)->tbl); \ 606 #define HASH_DEL_IN_BKT(hh,head,hh_del) \ 608 if ((head).hh_head == hh_del) { \ 609 (head).hh_head = hh_del->hh_next; \ 611 if (hh_del->hh_prev) { \ 612 hh_del->hh_prev->hh_next = hh_del->hh_next; \ 614 if (hh_del->hh_next) { \ 615 hh_del->hh_next->hh_prev = hh_del->hh_prev; \ 647 #define HASH_EXPAND_BUCKETS(tbl) \ 650 unsigned _he_bkt_i; \ 651 struct UT_hash_handle *_he_thh, *_he_hh_nxt; \ 652 UT_hash_bucket *_he_new_buckets, *_he_newbkt; \ 653 _he_new_buckets = (UT_hash_bucket*)uthash_malloc( \ 654 2 * tbl->num_buckets * sizeof(struct UT_hash_bucket)); \ 655 if (!_he_new_buckets) { uthash_fatal( "out of memory"); } \ 656 memset(_he_new_buckets, 0, \ 657 2 * tbl->num_buckets * sizeof(struct UT_hash_bucket)); \ 658 tbl->ideal_chain_maxlen = \ 659 (tbl->num_items >> (tbl->log2_num_buckets+1)) + \ 660 ((tbl->num_items & ((tbl->num_buckets*2)-1)) ? 1 : 0); \ 661 tbl->nonideal_items = 0; \ 662 for(_he_bkt_i = 0; _he_bkt_i < tbl->num_buckets; _he_bkt_i++) \ 664 _he_thh = tbl->buckets[ _he_bkt_i ].hh_head; \ 666 _he_hh_nxt = _he_thh->hh_next; \ 667 HASH_TO_BKT( _he_thh->hashv, tbl->num_buckets*2, _he_bkt); \ 668 _he_newbkt = &(_he_new_buckets[ _he_bkt ]); \ 669 if (++(_he_newbkt->count) > tbl->ideal_chain_maxlen) { \ 670 tbl->nonideal_items++; \ 671 _he_newbkt->expand_mult = _he_newbkt->count / \ 672 tbl->ideal_chain_maxlen; \ 674 _he_thh->hh_prev = NULL; \ 675 _he_thh->hh_next = _he_newbkt->hh_head; \ 676 if (_he_newbkt->hh_head) _he_newbkt->hh_head->hh_prev = \ 678 _he_newbkt->hh_head = _he_thh; \ 679 _he_thh = _he_hh_nxt; \ 682 uthash_free( tbl->buckets, tbl->num_buckets*sizeof(struct UT_hash_bucket) ); \ 683 tbl->num_buckets *= 2; \ 684 tbl->log2_num_buckets++; \ 685 tbl->buckets = _he_new_buckets; \ 686 tbl->ineff_expands = (tbl->nonideal_items > (tbl->num_items >> 1)) ? \ 687 (tbl->ineff_expands+1) : 0; \ 688 if (tbl->ineff_expands > 1) { \ 690 uthash_noexpand_fyi(tbl); \ 692 uthash_expand_fyi(tbl); \ 699 #define HASH_SORT(head,cmpfcn) HASH_SRT(hh,head,cmpfcn) 700 #define HASH_SRT(hh,head,cmpfcn) \ 703 unsigned _hs_looping,_hs_nmerges,_hs_insize,_hs_psize,_hs_qsize; \ 704 struct UT_hash_handle *_hs_p, *_hs_q, *_hs_e, *_hs_list, *_hs_tail; \ 708 _hs_list = &((head)->hh); \ 709 while (_hs_looping) { \ 718 for ( _hs_i = 0; _hs_i < _hs_insize; _hs_i++ ) { \ 720 _hs_q = (UT_hash_handle*)((_hs_q->next) ? \ 721 ((void*)((char*)(_hs_q->next) + \ 722 (head)->hh.tbl->hho)) : NULL); \ 723 if (! (_hs_q) ) break; \ 725 _hs_qsize = _hs_insize; \ 726 while ((_hs_psize > 0) || ((_hs_qsize > 0) && _hs_q )) { \ 727 if (_hs_psize == 0) { \ 729 _hs_q = (UT_hash_handle*)((_hs_q->next) ? \ 730 ((void*)((char*)(_hs_q->next) + \ 731 (head)->hh.tbl->hho)) : NULL); \ 733 } else if ( (_hs_qsize == 0) || !(_hs_q) ) { \ 735 _hs_p = (UT_hash_handle*)((_hs_p->next) ? \ 736 ((void*)((char*)(_hs_p->next) + \ 737 (head)->hh.tbl->hho)) : NULL); \ 740 cmpfcn(DECLTYPE(head)(ELMT_FROM_HH((head)->hh.tbl,_hs_p)), \ 741 DECLTYPE(head)(ELMT_FROM_HH((head)->hh.tbl,_hs_q))) \ 744 _hs_p = (UT_hash_handle*)((_hs_p->next) ? \ 745 ((void*)((char*)(_hs_p->next) + \ 746 (head)->hh.tbl->hho)) : NULL); \ 750 _hs_q = (UT_hash_handle*)((_hs_q->next) ? \ 751 ((void*)((char*)(_hs_q->next) + \ 752 (head)->hh.tbl->hho)) : NULL); \ 756 _hs_tail->next = ((_hs_e) ? \ 757 ELMT_FROM_HH((head)->hh.tbl,_hs_e) : NULL); \ 761 _hs_e->prev = ((_hs_tail) ? \ 762 ELMT_FROM_HH((head)->hh.tbl,_hs_tail) : NULL); \ 767 _hs_tail->next = NULL; \ 768 if ( _hs_nmerges <= 1 ) { \ 770 (head)->hh.tbl->tail = _hs_tail; \ 771 DECLTYPE_ASSIGN(head,ELMT_FROM_HH((head)->hh.tbl, _hs_list)); \ 775 HASH_FSCK(hh,head); \ 784 #define HASH_SELECT(hh_dst, dst, hh_src, src, cond) \ 786 unsigned _src_bkt, _dst_bkt; \ 787 void *_last_elt=NULL, *_elt; \ 788 UT_hash_handle *_src_hh, *_dst_hh, *_last_elt_hh=NULL; \ 789 ptrdiff_t _dst_hho = ((char*)(&(dst)->hh_dst) - (char*)(dst)); \ 791 for(_src_bkt=0; _src_bkt < (src)->hh_src.tbl->num_buckets; _src_bkt++) { \ 792 for(_src_hh = (src)->hh_src.tbl->buckets[_src_bkt].hh_head; \ 794 _src_hh = _src_hh->hh_next) { \ 795 _elt = ELMT_FROM_HH((src)->hh_src.tbl, _src_hh); \ 797 _dst_hh = (UT_hash_handle*)(((char*)_elt) + _dst_hho); \ 798 _dst_hh->key = _src_hh->key; \ 799 _dst_hh->keylen = _src_hh->keylen; \ 800 _dst_hh->hashv = _src_hh->hashv; \ 801 _dst_hh->prev = _last_elt; \ 802 _dst_hh->next = NULL; \ 803 if (_last_elt_hh) { _last_elt_hh->next = _elt; } \ 805 DECLTYPE_ASSIGN(dst,_elt); \ 806 HASH_MAKE_TABLE(hh_dst,dst); \ 808 _dst_hh->tbl = (dst)->hh_dst.tbl; \ 810 HASH_TO_BKT(_dst_hh->hashv, _dst_hh->tbl->num_buckets, _dst_bkt); \ 811 HASH_ADD_TO_BKT(_dst_hh->tbl->buckets[_dst_bkt],_dst_hh); \ 812 (dst)->hh_dst.tbl->num_items++; \ 814 _last_elt_hh = _dst_hh; \ 819 HASH_FSCK(hh_dst,dst); \ 822 #define HASH_CLEAR(hh,head) \ 825 uthash_free((head)->hh.tbl->buckets, \ 826 (head)->hh.tbl->num_buckets*sizeof(struct UT_hash_bucket)); \ 827 HASH_BLOOM_FREE((head)->hh.tbl); \ 828 uthash_free((head)->hh.tbl, sizeof(UT_hash_table)); \ 834 #define HASH_ITER(hh,head,el,tmp) \ 835 for((el)=(head), (*(char**)(&(tmp)))=(char*)((head)?(head)->hh.next:NULL); \ 836 el; (el)=(tmp),(*(char**)(&(tmp)))=(char*)((tmp)?(tmp)->hh.next:NULL)) 838 #define HASH_ITER(hh,head,el,tmp) \ 839 for((el)=(head),(tmp)=DECLTYPE(el)((head)?(head)->hh.next:NULL); \ 840 el; (el)=(tmp),(tmp)=DECLTYPE(el)((tmp)?(tmp)->hh.next:NULL)) 844 #define HASH_COUNT(head) HASH_CNT(hh,head) 845 #define HASH_CNT(hh,head) ((head)?((head)->hh.tbl->num_items):0) 868 #define HASH_SIGNATURE 0xa0111fe1 869 #define HASH_BLOOM_SIGNATURE 0xb12220f2
struct UT_hash_table * tbl
struct UT_hash_handle * hh_prev
struct UT_hash_handle * tail
struct UT_hash_bucket UT_hash_bucket
struct UT_hash_handle * hh_next
unsigned ideal_chain_maxlen
struct UT_hash_handle * hh_head
struct UT_hash_table UT_hash_table
struct UT_hash_handle UT_hash_handle