uthash.h 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943
  1. /*
  2. Copyright (c) 2003-2010, Troy D. Hanson http://uthash.sourceforge.net All rights reserved.
  3. SPDX-License-Identifier: BSD-1-Clause
  4. */
  5. #ifndef UTHASH_H
  6. #define UTHASH_H
  7. #include <string.h> /* memcmp,strlen */
  8. #include <stddef.h> /* ptrdiff_t */
  9. /* These macros use decltype or the earlier __typeof GNU extension.
  10. As decltype is only available in newer compilers (VS2010 or gcc 4.3+
  11. when compiling c++ source) this code uses whatever method is needed
  12. or, for VS2008 where neither is available, uses casting workarounds. */
  13. #ifdef _MSC_VER /* MS compiler */
  14. #if _MSC_VER >= 1600 && __cplusplus /* VS2010 or newer in C++ mode */
  15. #define DECLTYPE(x) (decltype(x))
  16. #else /* VS2008 or older (or VS2010 in C mode) */
  17. #define NO_DECLTYPE
  18. #define DECLTYPE(x)
  19. #endif
  20. #else /* GNU, Sun and other compilers */
  21. #define DECLTYPE(x) (__typeof(x))
  22. #endif
  23. #ifdef NO_DECLTYPE
  24. #define DECLTYPE_ASSIGN(dst,src) \
  25. do { \
  26. char **_da_dst = (char**)(&(dst)); \
  27. *_da_dst = (char*)(src); \
  28. } while(0)
  29. #else
  30. #define DECLTYPE_ASSIGN(dst,src) \
  31. do { \
  32. (dst) = DECLTYPE(dst)(src); \
  33. } while(0)
  34. #endif
  35. /* a number of the hash function use uint32_t which isn't defined on win32 */
  36. #ifdef _MSC_VER
  37. typedef unsigned int uint32_t;
  38. #else
  39. #include <inttypes.h> /* uint32_t */
  40. #endif
  41. #define UTHASH_VERSION 1.9.1
  42. #define uthash_fatal(msg) exit(-1) /* fatal error (out of memory,etc) */
  43. #define uthash_malloc(sz) malloc(sz) /* malloc fcn */
  44. #define uthash_free(ptr) free(ptr) /* free fcn */
  45. #define uthash_noexpand_fyi(tbl) /* can be defined to log noexpand */
  46. #define uthash_expand_fyi(tbl) /* can be defined to log expands */
  47. /* initial number of buckets */
  48. #define HASH_INITIAL_NUM_BUCKETS 32 /* initial number of buckets */
  49. #define HASH_INITIAL_NUM_BUCKETS_LOG2 5 /* lg2 of initial number of buckets */
  50. #define HASH_BKT_CAPACITY_THRESH 10 /* expand when bucket count reaches */
  51. /* calculate the element whose hash handle address is hhe */
  52. #define ELMT_FROM_HH(tbl,hhp) ((void*)(((char*)(hhp)) - ((tbl)->hho)))
  53. #define HASH_FIND(hh,head,keyptr,keylen,out) \
  54. do { \
  55. unsigned _hf_bkt,_hf_hashv; \
  56. out=NULL; \
  57. if (head) { \
  58. HASH_FCN(keyptr,keylen, (head)->hh.tbl->num_buckets, _hf_hashv, _hf_bkt); \
  59. if (HASH_BLOOM_TEST((head)->hh.tbl, _hf_hashv)) { \
  60. HASH_FIND_IN_BKT((head)->hh.tbl, hh, (head)->hh.tbl->buckets[ _hf_bkt ], \
  61. keyptr,keylen,out); \
  62. } \
  63. } \
  64. } while (0)
  65. #ifdef HASH_BLOOM
  66. #define HASH_BLOOM_BITLEN (1ULL << HASH_BLOOM)
  67. #define HASH_BLOOM_BYTELEN (HASH_BLOOM_BITLEN/8) + ((HASH_BLOOM_BITLEN%8) ? 1:0)
  68. #define HASH_BLOOM_MAKE(tbl) \
  69. do { \
  70. (tbl)->bloom_nbits = HASH_BLOOM; \
  71. (tbl)->bloom_bv = (uint8_t*)uthash_malloc(HASH_BLOOM_BYTELEN); \
  72. if (!((tbl)->bloom_bv)) { uthash_fatal( "out of memory"); } \
  73. memset((tbl)->bloom_bv, 0, HASH_BLOOM_BYTELEN); \
  74. (tbl)->bloom_sig = HASH_BLOOM_SIGNATURE; \
  75. } while (0);
  76. #define HASH_BLOOM_FREE(tbl) \
  77. do { \
  78. uthash_free((tbl)->bloom_bv); \
  79. } while (0);
  80. #define HASH_BLOOM_BITSET(bv,idx) (bv[(idx)/8] |= (1U << ((idx)%8)))
  81. #define HASH_BLOOM_BITTEST(bv,idx) (bv[(idx)/8] & (1U << ((idx)%8)))
  82. #define HASH_BLOOM_ADD(tbl,hashv) \
  83. HASH_BLOOM_BITSET((tbl)->bloom_bv, (hashv & (uint32_t)((1ULL << (tbl)->bloom_nbits) - 1)))
  84. #define HASH_BLOOM_TEST(tbl,hashv) \
  85. HASH_BLOOM_BITTEST((tbl)->bloom_bv, (hashv & (uint32_t)((1ULL << (tbl)->bloom_nbits) - 1)))
  86. #else
  87. #define HASH_BLOOM_MAKE(tbl)
  88. #define HASH_BLOOM_FREE(tbl)
  89. #define HASH_BLOOM_ADD(tbl,hashv)
  90. #define HASH_BLOOM_TEST(tbl,hashv) (1)
  91. #endif
  92. #define HASH_MAKE_TABLE(hh,head) \
  93. do { \
  94. (head)->hh.tbl = (UT_hash_table*)uthash_malloc( \
  95. sizeof(UT_hash_table)); \
  96. if (!((head)->hh.tbl)) { uthash_fatal( "out of memory"); } \
  97. memset((head)->hh.tbl, 0, sizeof(UT_hash_table)); \
  98. (head)->hh.tbl->tail = &((head)->hh); \
  99. (head)->hh.tbl->num_buckets = HASH_INITIAL_NUM_BUCKETS; \
  100. (head)->hh.tbl->log2_num_buckets = HASH_INITIAL_NUM_BUCKETS_LOG2; \
  101. (head)->hh.tbl->hho = (char*)(&(head)->hh) - (char*)(head); \
  102. (head)->hh.tbl->buckets = (UT_hash_bucket*)uthash_malloc( \
  103. HASH_INITIAL_NUM_BUCKETS*sizeof(struct UT_hash_bucket)); \
  104. if (! (head)->hh.tbl->buckets) { uthash_fatal( "out of memory"); } \
  105. memset((head)->hh.tbl->buckets, 0, \
  106. HASH_INITIAL_NUM_BUCKETS*sizeof(struct UT_hash_bucket)); \
  107. HASH_BLOOM_MAKE((head)->hh.tbl); \
  108. (head)->hh.tbl->signature = HASH_SIGNATURE; \
  109. } while(0)
  110. #define HASH_ADD(hh,head,fieldname,keylen_in,add) \
  111. HASH_ADD_KEYPTR(hh,head,&add->fieldname,keylen_in,add)
  112. #define HASH_ADD_KEYPTR(hh,head,keyptr,keylen_in,add) \
  113. do { \
  114. unsigned _ha_bkt; \
  115. (add)->hh.next = NULL; \
  116. (add)->hh.key = (char*)keyptr; \
  117. (add)->hh.keylen = keylen_in; \
  118. if (!(head)) { \
  119. head = (add); \
  120. (head)->hh.prev = NULL; \
  121. HASH_MAKE_TABLE(hh,head); \
  122. } else { \
  123. (head)->hh.tbl->tail->next = (add); \
  124. (add)->hh.prev = ELMT_FROM_HH((head)->hh.tbl, (head)->hh.tbl->tail); \
  125. (head)->hh.tbl->tail = &((add)->hh); \
  126. } \
  127. (head)->hh.tbl->num_items++; \
  128. (add)->hh.tbl = (head)->hh.tbl; \
  129. HASH_FCN(keyptr,keylen_in, (head)->hh.tbl->num_buckets, \
  130. (add)->hh.hashv, _ha_bkt); \
  131. HASH_ADD_TO_BKT((head)->hh.tbl->buckets[_ha_bkt],&(add)->hh); \
  132. HASH_BLOOM_ADD((head)->hh.tbl,(add)->hh.hashv); \
  133. HASH_EMIT_KEY(hh,head,keyptr,keylen_in); \
  134. HASH_FSCK(hh,head); \
  135. } while(0)
  136. #define HASH_TO_BKT( hashv, num_bkts, bkt ) \
  137. do { \
  138. bkt = ((hashv) & ((num_bkts) - 1)); \
  139. } while(0)
  140. /* delete "delptr" from the hash table.
  141. * "the usual" patch-up process for the app-order doubly-linked-list.
  142. * The use of _hd_hh_del below deserves special explanation.
  143. * These used to be expressed using (delptr) but that led to a bug
  144. * if someone used the same symbol for the head and deletee, like
  145. * HASH_DELETE(hh,users,users);
  146. * We want that to work, but by changing the head (users) below
  147. * we were forfeiting our ability to further refer to the deletee (users)
  148. * in the patch-up process. Solution: use scratch space to
  149. * copy the deletee pointer, then the latter references are via that
  150. * scratch pointer rather than through the repointed (users) symbol.
  151. */
  152. #define HASH_DELETE(hh,head,delptr) \
  153. do { \
  154. unsigned _hd_bkt; \
  155. struct UT_hash_handle *_hd_hh_del; \
  156. if ( ((delptr)->hh.prev == NULL) && ((delptr)->hh.next == NULL) ) { \
  157. uthash_free((head)->hh.tbl->buckets ); \
  158. HASH_BLOOM_FREE((head)->hh.tbl); \
  159. uthash_free((head)->hh.tbl); \
  160. head = NULL; \
  161. } else { \
  162. _hd_hh_del = &((delptr)->hh); \
  163. if ((delptr) == ELMT_FROM_HH((head)->hh.tbl,(head)->hh.tbl->tail)) { \
  164. (head)->hh.tbl->tail = \
  165. (UT_hash_handle*)((char*)((delptr)->hh.prev) + \
  166. (head)->hh.tbl->hho); \
  167. } \
  168. if ((delptr)->hh.prev) { \
  169. ((UT_hash_handle*)((char*)((delptr)->hh.prev) + \
  170. (head)->hh.tbl->hho))->next = (delptr)->hh.next; \
  171. } else { \
  172. DECLTYPE_ASSIGN(head,(delptr)->hh.next); \
  173. } \
  174. if (_hd_hh_del->next) { \
  175. ((UT_hash_handle*)((char*)_hd_hh_del->next + \
  176. (head)->hh.tbl->hho))->prev = \
  177. _hd_hh_del->prev; \
  178. } \
  179. HASH_TO_BKT( _hd_hh_del->hashv, (head)->hh.tbl->num_buckets, _hd_bkt); \
  180. HASH_DEL_IN_BKT(hh,(head)->hh.tbl->buckets[_hd_bkt], _hd_hh_del); \
  181. (head)->hh.tbl->num_items--; \
  182. } \
  183. HASH_FSCK(hh,head); \
  184. } while (0)
  185. /* convenience forms of HASH_FIND/HASH_ADD/HASH_DEL */
  186. #define HASH_FIND_STR(head,findstr,out) \
  187. HASH_FIND(hh,head,findstr,strlen(findstr),out)
  188. #define HASH_ADD_STR(head,strfield,add) \
  189. HASH_ADD(hh,head,strfield,strlen(add->strfield),add)
  190. #define HASH_FIND_INT(head,findint,out) \
  191. HASH_FIND(hh,head,findint,sizeof(int),out)
  192. #define HASH_ADD_INT(head,intfield,add) \
  193. HASH_ADD(hh,head,intfield,sizeof(int),add)
  194. #define HASH_FIND_PTR(head,findptr,out) \
  195. HASH_FIND(hh,head,findptr,sizeof(void *),out)
  196. #define HASH_ADD_PTR(head,ptrfield,add) \
  197. HASH_ADD(hh,head,ptrfield,sizeof(void *),add)
  198. #define HASH_DEL(head,delptr) \
  199. HASH_DELETE(hh,head,delptr)
  200. /* HASH_FSCK checks hash integrity on every add/delete when HASH_DEBUG is defined.
  201. * This is for uthash developer only; it compiles away if HASH_DEBUG isn't defined.
  202. */
  203. #ifdef HASH_DEBUG
  204. #define HASH_OOPS(...) do { fprintf(stderr,__VA_ARGS__); exit(-1); } while (0)
  205. #define HASH_FSCK(hh,head) \
  206. do { \
  207. unsigned _bkt_i; \
  208. unsigned _count, _bkt_count; \
  209. char *_prev; \
  210. struct UT_hash_handle *_thh; \
  211. if (head) { \
  212. _count = 0; \
  213. for( _bkt_i = 0; _bkt_i < (head)->hh.tbl->num_buckets; _bkt_i++) { \
  214. _bkt_count = 0; \
  215. _thh = (head)->hh.tbl->buckets[_bkt_i].hh_head; \
  216. _prev = NULL; \
  217. while (_thh) { \
  218. if (_prev != (char*)(_thh->hh_prev)) { \
  219. HASH_OOPS("invalid hh_prev %p, actual %p\n", \
  220. _thh->hh_prev, _prev ); \
  221. } \
  222. _bkt_count++; \
  223. _prev = (char*)(_thh); \
  224. _thh = _thh->hh_next; \
  225. } \
  226. _count += _bkt_count; \
  227. if ((head)->hh.tbl->buckets[_bkt_i].count != _bkt_count) { \
  228. HASH_OOPS("invalid bucket count %d, actual %d\n", \
  229. (head)->hh.tbl->buckets[_bkt_i].count, _bkt_count); \
  230. } \
  231. } \
  232. if (_count != (head)->hh.tbl->num_items) { \
  233. HASH_OOPS("invalid hh item count %d, actual %d\n", \
  234. (head)->hh.tbl->num_items, _count ); \
  235. } \
  236. /* traverse hh in app order; check next/prev integrity, count */ \
  237. _count = 0; \
  238. _prev = NULL; \
  239. _thh = &(head)->hh; \
  240. while (_thh) { \
  241. _count++; \
  242. if (_prev !=(char*)(_thh->prev)) { \
  243. HASH_OOPS("invalid prev %p, actual %p\n", \
  244. _thh->prev, _prev ); \
  245. } \
  246. _prev = (char*)ELMT_FROM_HH((head)->hh.tbl, _thh); \
  247. _thh = ( _thh->next ? (UT_hash_handle*)((char*)(_thh->next) + \
  248. (head)->hh.tbl->hho) : NULL ); \
  249. } \
  250. if (_count != (head)->hh.tbl->num_items) { \
  251. HASH_OOPS("invalid app item count %d, actual %d\n", \
  252. (head)->hh.tbl->num_items, _count ); \
  253. } \
  254. } \
  255. } while (0)
  256. #else
  257. #define HASH_FSCK(hh,head)
  258. #endif
  259. /* When compiled with -DHASH_EMIT_KEYS, length-prefixed keys are emitted to
  260. * the descriptor to which this macro is defined for tuning the hash function.
  261. * The app can #include <unistd.h> to get the prototype for write(2). */
  262. #ifdef HASH_EMIT_KEYS
  263. #define HASH_EMIT_KEY(hh,head,keyptr,fieldlen) \
  264. do { \
  265. unsigned _klen = fieldlen; \
  266. write(HASH_EMIT_KEYS, &_klen, sizeof(_klen)); \
  267. write(HASH_EMIT_KEYS, keyptr, fieldlen); \
  268. } while (0)
  269. #else
  270. #define HASH_EMIT_KEY(hh,head,keyptr,fieldlen)
  271. #endif
  272. /* default to Jenkin's hash unless overridden e.g. DHASH_FUNCTION=HASH_SAX */
  273. #ifdef HASH_FUNCTION
  274. #define HASH_FCN HASH_FUNCTION
  275. #else
  276. #define HASH_FCN HASH_JEN
  277. #endif
  278. /* The Bernstein hash function, used in Perl prior to v5.6 */
  279. #define HASH_BER(key,keylen,num_bkts,hashv,bkt) \
  280. do { \
  281. unsigned _hb_keylen=keylen; \
  282. char *_hb_key=(char*)key; \
  283. (hashv) = 0; \
  284. while (_hb_keylen--) { (hashv) = ((hashv) * 33) + *_hb_key++; } \
  285. bkt = (hashv) & (num_bkts-1); \
  286. } while (0)
  287. /* SAX/FNV/OAT/JEN hash functions are macro variants of those listed at
  288. * http://eternallyconfuzzled.com/tuts/algorithms/jsw_tut_hashing.aspx */
  289. #define HASH_SAX(key,keylen,num_bkts,hashv,bkt) \
  290. do { \
  291. unsigned _sx_i; \
  292. char *_hs_key=(char*)key; \
  293. hashv = 0; \
  294. for(_sx_i=0; _sx_i < keylen; _sx_i++) \
  295. hashv ^= (hashv << 5) + (hashv >> 2) + _hs_key[_sx_i]; \
  296. bkt = hashv & (num_bkts-1); \
  297. } while (0)
  298. #define HASH_FNV(key,keylen,num_bkts,hashv,bkt) \
  299. do { \
  300. unsigned _fn_i; \
  301. char *_hf_key=(char*)key; \
  302. hashv = 2166136261UL; \
  303. for(_fn_i=0; _fn_i < keylen; _fn_i++) \
  304. hashv = (hashv * 16777619) ^ _hf_key[_fn_i]; \
  305. bkt = hashv & (num_bkts-1); \
  306. } while(0);
  307. #define HASH_OAT(key,keylen,num_bkts,hashv,bkt) \
  308. do { \
  309. unsigned _ho_i; \
  310. char *_ho_key=(char*)key; \
  311. hashv = 0; \
  312. for(_ho_i=0; _ho_i < keylen; _ho_i++) { \
  313. hashv += _ho_key[_ho_i]; \
  314. hashv += (hashv << 10); \
  315. hashv ^= (hashv >> 6); \
  316. } \
  317. hashv += (hashv << 3); \
  318. hashv ^= (hashv >> 11); \
  319. hashv += (hashv << 15); \
  320. bkt = hashv & (num_bkts-1); \
  321. } while(0)
  322. #define HASH_JEN_MIX(a,b,c) \
  323. do { \
  324. a -= b; a -= c; a ^= ( c >> 13 ); \
  325. b -= c; b -= a; b ^= ( a << 8 ); \
  326. c -= a; c -= b; c ^= ( b >> 13 ); \
  327. a -= b; a -= c; a ^= ( c >> 12 ); \
  328. b -= c; b -= a; b ^= ( a << 16 ); \
  329. c -= a; c -= b; c ^= ( b >> 5 ); \
  330. a -= b; a -= c; a ^= ( c >> 3 ); \
  331. b -= c; b -= a; b ^= ( a << 10 ); \
  332. c -= a; c -= b; c ^= ( b >> 15 ); \
  333. } while (0)
  334. #define HASH_JEN(key,keylen,num_bkts,hashv,bkt) \
  335. do { \
  336. unsigned _hj_i,_hj_j,_hj_k; \
  337. char *_hj_key=(char*)key; \
  338. hashv = 0xfeedbeef; \
  339. _hj_i = _hj_j = 0x9e3779b9; \
  340. _hj_k = keylen; \
  341. while (_hj_k >= 12) { \
  342. _hj_i += (_hj_key[0] + ( (unsigned)_hj_key[1] << 8 ) \
  343. + ( (unsigned)_hj_key[2] << 16 ) \
  344. + ( (unsigned)_hj_key[3] << 24 ) ); \
  345. _hj_j += (_hj_key[4] + ( (unsigned)_hj_key[5] << 8 ) \
  346. + ( (unsigned)_hj_key[6] << 16 ) \
  347. + ( (unsigned)_hj_key[7] << 24 ) ); \
  348. hashv += (_hj_key[8] + ( (unsigned)_hj_key[9] << 8 ) \
  349. + ( (unsigned)_hj_key[10] << 16 ) \
  350. + ( (unsigned)_hj_key[11] << 24 ) ); \
  351. \
  352. HASH_JEN_MIX(_hj_i, _hj_j, hashv); \
  353. \
  354. _hj_key += 12; \
  355. _hj_k -= 12; \
  356. } \
  357. hashv += keylen; \
  358. switch ( _hj_k ) { \
  359. case 11: hashv += ( (unsigned)_hj_key[10] << 24 ); \
  360. case 10: hashv += ( (unsigned)_hj_key[9] << 16 ); \
  361. case 9: hashv += ( (unsigned)_hj_key[8] << 8 ); \
  362. case 8: _hj_j += ( (unsigned)_hj_key[7] << 24 ); \
  363. case 7: _hj_j += ( (unsigned)_hj_key[6] << 16 ); \
  364. case 6: _hj_j += ( (unsigned)_hj_key[5] << 8 ); \
  365. case 5: _hj_j += _hj_key[4]; \
  366. case 4: _hj_i += ( (unsigned)_hj_key[3] << 24 ); \
  367. case 3: _hj_i += ( (unsigned)_hj_key[2] << 16 ); \
  368. case 2: _hj_i += ( (unsigned)_hj_key[1] << 8 ); \
  369. case 1: _hj_i += _hj_key[0]; \
  370. } \
  371. HASH_JEN_MIX(_hj_i, _hj_j, hashv); \
  372. bkt = hashv & (num_bkts-1); \
  373. } while(0)
  374. /* The Paul Hsieh hash function */
  375. #undef get16bits
  376. #if (defined(__GNUC__) && defined(__i386__)) || defined(__WATCOMC__) \
  377. || defined(_MSC_VER) || defined (__BORLANDC__) || defined (__TURBOC__)
  378. #define get16bits(d) (*((const uint16_t *) (d)))
  379. #endif
  380. #if !defined (get16bits)
  381. #define get16bits(d) ((((uint32_t)(((const uint8_t *)(d))[1])) << 8) \
  382. +(uint32_t)(((const uint8_t *)(d))[0]) )
  383. #endif
  384. #define HASH_SFH(key,keylen,num_bkts,hashv,bkt) \
  385. do { \
  386. char *_sfh_key=(char*)key; \
  387. uint32_t _sfh_tmp, _sfh_len = keylen; \
  388. \
  389. int _sfh_rem = _sfh_len & 3; \
  390. _sfh_len >>= 2; \
  391. hashv = 0xcafebabe; \
  392. \
  393. /* Main loop */ \
  394. for (;_sfh_len > 0; _sfh_len--) { \
  395. hashv += get16bits (_sfh_key); \
  396. _sfh_tmp = (get16bits (_sfh_key+2) << 11) ^ hashv; \
  397. hashv = (hashv << 16) ^ _sfh_tmp; \
  398. _sfh_key += 2*sizeof (uint16_t); \
  399. hashv += hashv >> 11; \
  400. } \
  401. \
  402. /* Handle end cases */ \
  403. switch (_sfh_rem) { \
  404. case 3: hashv += get16bits (_sfh_key); \
  405. hashv ^= hashv << 16; \
  406. hashv ^= _sfh_key[sizeof (uint16_t)] << 18; \
  407. hashv += hashv >> 11; \
  408. break; \
  409. case 2: hashv += get16bits (_sfh_key); \
  410. hashv ^= hashv << 11; \
  411. hashv += hashv >> 17; \
  412. break; \
  413. case 1: hashv += *_sfh_key; \
  414. hashv ^= hashv << 10; \
  415. hashv += hashv >> 1; \
  416. } \
  417. \
  418. /* Force "avalanching" of final 127 bits */ \
  419. hashv ^= hashv << 3; \
  420. hashv += hashv >> 5; \
  421. hashv ^= hashv << 4; \
  422. hashv += hashv >> 17; \
  423. hashv ^= hashv << 25; \
  424. hashv += hashv >> 6; \
  425. bkt = hashv & (num_bkts-1); \
  426. } while(0);
  427. #ifdef HASH_USING_NO_STRICT_ALIASING
  428. /* The MurmurHash exploits some CPU's (e.g. x86) tolerance for unaligned reads.
  429. * For other types of CPU's (e.g. Sparc) an unaligned read causes a bus error.
  430. * So MurmurHash comes in two versions, the faster unaligned one and the slower
  431. * aligned one. We only use the faster one on CPU's where we know it's safe.
  432. *
  433. * Note the preprocessor built-in defines can be emitted using:
  434. *
  435. * gcc -m64 -dM -E - < /dev/null (on gcc)
  436. * cc -## a.c (where a.c is a simple test file) (Sun Studio)
  437. */
  438. #if (defined(__i386__) || defined(__x86_64__))
  439. #define HASH_MUR HASH_MUR_UNALIGNED
  440. #else
  441. #define HASH_MUR HASH_MUR_ALIGNED
  442. #endif
  443. /* Appleby's MurmurHash fast version for unaligned-tolerant archs like i386 */
  444. #define HASH_MUR_UNALIGNED(key,keylen,num_bkts,hashv,bkt) \
  445. do { \
  446. const unsigned int _mur_m = 0x5bd1e995; \
  447. const int _mur_r = 24; \
  448. hashv = 0xcafebabe ^ keylen; \
  449. char *_mur_key = (char *)key; \
  450. uint32_t _mur_tmp, _mur_len = keylen; \
  451. \
  452. for (;_mur_len >= 4; _mur_len-=4) { \
  453. _mur_tmp = *(uint32_t *)_mur_key; \
  454. _mur_tmp *= _mur_m; \
  455. _mur_tmp ^= _mur_tmp >> _mur_r; \
  456. _mur_tmp *= _mur_m; \
  457. hashv *= _mur_m; \
  458. hashv ^= _mur_tmp; \
  459. _mur_key += 4; \
  460. } \
  461. \
  462. switch(_mur_len) \
  463. { \
  464. case 3: hashv ^= _mur_key[2] << 16; \
  465. case 2: hashv ^= _mur_key[1] << 8; \
  466. case 1: hashv ^= _mur_key[0]; \
  467. hashv *= _mur_m; \
  468. }; \
  469. \
  470. hashv ^= hashv >> 13; \
  471. hashv *= _mur_m; \
  472. hashv ^= hashv >> 15; \
  473. \
  474. bkt = hashv & (num_bkts-1); \
  475. } while(0)
  476. /* Appleby's MurmurHash version for alignment-sensitive archs like Sparc */
  477. #define HASH_MUR_ALIGNED(key,keylen,num_bkts,hashv,bkt) \
  478. do { \
  479. const unsigned int _mur_m = 0x5bd1e995; \
  480. const int _mur_r = 24; \
  481. hashv = 0xcafebabe ^ keylen; \
  482. char *_mur_key = (char *)key; \
  483. uint32_t _mur_len = keylen; \
  484. int _mur_align = (int)_mur_key & 3; \
  485. \
  486. if (_mur_align && (_mur_len >= 4)) { \
  487. unsigned _mur_t = 0, _mur_d = 0; \
  488. switch(_mur_align) { \
  489. case 1: _mur_t |= _mur_key[2] << 16; \
  490. case 2: _mur_t |= _mur_key[1] << 8; \
  491. case 3: _mur_t |= _mur_key[0]; \
  492. } \
  493. _mur_t <<= (8 * _mur_align); \
  494. _mur_key += 4-_mur_align; \
  495. _mur_len -= 4-_mur_align; \
  496. int _mur_sl = 8 * (4-_mur_align); \
  497. int _mur_sr = 8 * _mur_align; \
  498. \
  499. for (;_mur_len >= 4; _mur_len-=4) { \
  500. _mur_d = *(unsigned *)_mur_key; \
  501. _mur_t = (_mur_t >> _mur_sr) | (_mur_d << _mur_sl); \
  502. unsigned _mur_k = _mur_t; \
  503. _mur_k *= _mur_m; \
  504. _mur_k ^= _mur_k >> _mur_r; \
  505. _mur_k *= _mur_m; \
  506. hashv *= _mur_m; \
  507. hashv ^= _mur_k; \
  508. _mur_t = _mur_d; \
  509. _mur_key += 4; \
  510. } \
  511. _mur_d = 0; \
  512. if(_mur_len >= _mur_align) { \
  513. switch(_mur_align) { \
  514. case 3: _mur_d |= _mur_key[2] << 16; \
  515. case 2: _mur_d |= _mur_key[1] << 8; \
  516. case 1: _mur_d |= _mur_key[0]; \
  517. } \
  518. unsigned _mur_k = (_mur_t >> _mur_sr) | (_mur_d << _mur_sl); \
  519. _mur_k *= _mur_m; \
  520. _mur_k ^= _mur_k >> _mur_r; \
  521. _mur_k *= _mur_m; \
  522. hashv *= _mur_m; \
  523. hashv ^= _mur_k; \
  524. _mur_k += _mur_align; \
  525. _mur_len -= _mur_align; \
  526. \
  527. switch(_mur_len) \
  528. { \
  529. case 3: hashv ^= _mur_key[2] << 16; \
  530. case 2: hashv ^= _mur_key[1] << 8; \
  531. case 1: hashv ^= _mur_key[0]; \
  532. hashv *= _mur_m; \
  533. } \
  534. } else { \
  535. switch(_mur_len) \
  536. { \
  537. case 3: _mur_d ^= _mur_key[2] << 16; \
  538. case 2: _mur_d ^= _mur_key[1] << 8; \
  539. case 1: _mur_d ^= _mur_key[0]; \
  540. case 0: hashv ^= (_mur_t >> _mur_sr) | (_mur_d << _mur_sl); \
  541. hashv *= _mur_m; \
  542. } \
  543. } \
  544. \
  545. hashv ^= hashv >> 13; \
  546. hashv *= _mur_m; \
  547. hashv ^= hashv >> 15; \
  548. } else { \
  549. for (;_mur_len >= 4; _mur_len-=4) { \
  550. unsigned _mur_k = *(unsigned*)_mur_key; \
  551. _mur_k *= _mur_m; \
  552. _mur_k ^= _mur_k >> _mur_r; \
  553. _mur_k *= _mur_m; \
  554. hashv *= _mur_m; \
  555. hashv ^= _mur_k; \
  556. _mur_key += 4; \
  557. } \
  558. switch(_mur_len) \
  559. { \
  560. case 3: hashv ^= _mur_key[2] << 16; \
  561. case 2: hashv ^= _mur_key[1] << 8; \
  562. case 1: hashv ^= _mur_key[0]; \
  563. hashv *= _mur_m; \
  564. } \
  565. \
  566. hashv ^= hashv >> 13; \
  567. hashv *= _mur_m; \
  568. hashv ^= hashv >> 15; \
  569. } \
  570. bkt = hashv & (num_bkts-1); \
  571. } while(0)
  572. #endif /* HASH_USING_NO_STRICT_ALIASING */
  573. /* key comparison function; return 0 if keys equal */
  574. #define HASH_KEYCMP(a,b,len) memcmp(a,b,len)
  575. /* iterate over items in a known bucket to find desired item */
  576. #define HASH_FIND_IN_BKT(tbl,hh,head,keyptr,keylen_in,out) \
  577. do { \
  578. if (head.hh_head) DECLTYPE_ASSIGN(out,ELMT_FROM_HH(tbl,head.hh_head)); \
  579. else out=NULL; \
  580. while (out) { \
  581. if (out->hh.keylen == keylen_in) { \
  582. if ((HASH_KEYCMP(out->hh.key,keyptr,keylen_in)) == 0) break; \
  583. } \
  584. if (out->hh.hh_next) DECLTYPE_ASSIGN(out,ELMT_FROM_HH(tbl,out->hh.hh_next)); \
  585. else out = NULL; \
  586. } \
  587. } while(0)
  588. /* add an item to a bucket */
  589. #define HASH_ADD_TO_BKT(head,addhh) \
  590. do { \
  591. head.count++; \
  592. (addhh)->hh_next = head.hh_head; \
  593. (addhh)->hh_prev = NULL; \
  594. if (head.hh_head) { (head).hh_head->hh_prev = (addhh); } \
  595. (head).hh_head=addhh; \
  596. if (head.count >= ((head.expand_mult+1) * HASH_BKT_CAPACITY_THRESH) \
  597. && (addhh)->tbl->noexpand != 1) { \
  598. HASH_EXPAND_BUCKETS((addhh)->tbl); \
  599. } \
  600. } while(0)
  601. /* remove an item from a given bucket */
  602. #define HASH_DEL_IN_BKT(hh,head,hh_del) \
  603. (head).count--; \
  604. if ((head).hh_head == hh_del) { \
  605. (head).hh_head = hh_del->hh_next; \
  606. } \
  607. if (hh_del->hh_prev) { \
  608. hh_del->hh_prev->hh_next = hh_del->hh_next; \
  609. } \
  610. if (hh_del->hh_next) { \
  611. hh_del->hh_next->hh_prev = hh_del->hh_prev; \
  612. }
  613. /* Bucket expansion has the effect of doubling the number of buckets
  614. * and redistributing the items into the new buckets. Ideally the
  615. * items will distribute more or less evenly into the new buckets
  616. * (the extent to which this is true is a measure of the quality of
  617. * the hash function as it applies to the key domain).
  618. *
  619. * With the items distributed into more buckets, the chain length
  620. * (item count) in each bucket is reduced. Thus by expanding buckets
  621. * the hash keeps a bound on the chain length. This bounded chain
  622. * length is the essence of how a hash provides constant time lookup.
  623. *
  624. * The calculation of tbl->ideal_chain_maxlen below deserves some
  625. * explanation. First, keep in mind that we're calculating the ideal
  626. * maximum chain length based on the *new* (doubled) bucket count.
  627. * In fractions this is just n/b (n=number of items,b=new num buckets).
  628. * Since the ideal chain length is an integer, we want to calculate
  629. * ceil(n/b). We don't depend on floating point arithmetic in this
  630. * hash, so to calculate ceil(n/b) with integers we could write
  631. *
  632. * ceil(n/b) = (n/b) + ((n%b)?1:0)
  633. *
  634. * and in fact a previous version of this hash did just that.
  635. * But now we have improved things a bit by recognizing that b is
  636. * always a power of two. We keep its base 2 log handy (call it lb),
  637. * so now we can write this with a bit shift and logical AND:
  638. *
  639. * ceil(n/b) = (n>>lb) + ( (n & (b-1)) ? 1:0)
  640. *
  641. */
  642. #define HASH_EXPAND_BUCKETS(tbl) \
  643. do { \
  644. unsigned _he_bkt; \
  645. unsigned _he_bkt_i; \
  646. struct UT_hash_handle *_he_thh, *_he_hh_nxt; \
  647. UT_hash_bucket *_he_new_buckets, *_he_newbkt; \
  648. _he_new_buckets = (UT_hash_bucket*)uthash_malloc( \
  649. 2 * tbl->num_buckets * sizeof(struct UT_hash_bucket)); \
  650. if (!_he_new_buckets) { uthash_fatal( "out of memory"); } \
  651. memset(_he_new_buckets, 0, \
  652. 2 * tbl->num_buckets * sizeof(struct UT_hash_bucket)); \
  653. tbl->ideal_chain_maxlen = \
  654. (tbl->num_items >> (tbl->log2_num_buckets+1)) + \
  655. ((tbl->num_items & ((tbl->num_buckets*2)-1)) ? 1 : 0); \
  656. tbl->nonideal_items = 0; \
  657. for(_he_bkt_i = 0; _he_bkt_i < tbl->num_buckets; _he_bkt_i++) \
  658. { \
  659. _he_thh = tbl->buckets[ _he_bkt_i ].hh_head; \
  660. while (_he_thh) { \
  661. _he_hh_nxt = _he_thh->hh_next; \
  662. HASH_TO_BKT( _he_thh->hashv, tbl->num_buckets*2, _he_bkt); \
  663. _he_newbkt = &(_he_new_buckets[ _he_bkt ]); \
  664. if (++(_he_newbkt->count) > tbl->ideal_chain_maxlen) { \
  665. tbl->nonideal_items++; \
  666. _he_newbkt->expand_mult = _he_newbkt->count / \
  667. tbl->ideal_chain_maxlen; \
  668. } \
  669. _he_thh->hh_prev = NULL; \
  670. _he_thh->hh_next = _he_newbkt->hh_head; \
  671. if (_he_newbkt->hh_head) _he_newbkt->hh_head->hh_prev = \
  672. _he_thh; \
  673. _he_newbkt->hh_head = _he_thh; \
  674. _he_thh = _he_hh_nxt; \
  675. } \
  676. } \
  677. tbl->num_buckets *= 2; \
  678. tbl->log2_num_buckets++; \
  679. uthash_free( tbl->buckets ); \
  680. tbl->buckets = _he_new_buckets; \
  681. tbl->ineff_expands = (tbl->nonideal_items > (tbl->num_items >> 1)) ? \
  682. (tbl->ineff_expands+1) : 0; \
  683. if (tbl->ineff_expands > 1) { \
  684. tbl->noexpand=1; \
  685. uthash_noexpand_fyi(tbl); \
  686. } \
  687. uthash_expand_fyi(tbl); \
  688. } while(0)
  689. /* This is an adaptation of Simon Tatham's O(n log(n)) mergesort */
  690. /* Note that HASH_SORT assumes the hash handle name to be hh.
  691. * HASH_SRT was added to allow the hash handle name to be passed in. */
  692. #define HASH_SORT(head,cmpfcn) HASH_SRT(hh,head,cmpfcn)
  693. #define HASH_SRT(hh,head,cmpfcn) \
  694. do { \
  695. unsigned _hs_i; \
  696. unsigned _hs_looping,_hs_nmerges,_hs_insize,_hs_psize,_hs_qsize; \
  697. struct UT_hash_handle *_hs_p, *_hs_q, *_hs_e, *_hs_list, *_hs_tail; \
  698. if (head) { \
  699. _hs_insize = 1; \
  700. _hs_looping = 1; \
  701. _hs_list = &((head)->hh); \
  702. while (_hs_looping) { \
  703. _hs_p = _hs_list; \
  704. _hs_list = NULL; \
  705. _hs_tail = NULL; \
  706. _hs_nmerges = 0; \
  707. while (_hs_p) { \
  708. _hs_nmerges++; \
  709. _hs_q = _hs_p; \
  710. _hs_psize = 0; \
  711. for ( _hs_i = 0; _hs_i < _hs_insize; _hs_i++ ) { \
  712. _hs_psize++; \
  713. _hs_q = (UT_hash_handle*)((_hs_q->next) ? \
  714. ((void*)((char*)(_hs_q->next) + \
  715. (head)->hh.tbl->hho)) : NULL); \
  716. if (! (_hs_q) ) break; \
  717. } \
  718. _hs_qsize = _hs_insize; \
  719. while ((_hs_psize > 0) || ((_hs_qsize > 0) && _hs_q )) { \
  720. if (_hs_psize == 0) { \
  721. _hs_e = _hs_q; \
  722. _hs_q = (UT_hash_handle*)((_hs_q->next) ? \
  723. ((void*)((char*)(_hs_q->next) + \
  724. (head)->hh.tbl->hho)) : NULL); \
  725. _hs_qsize--; \
  726. } else if ( (_hs_qsize == 0) || !(_hs_q) ) { \
  727. _hs_e = _hs_p; \
  728. _hs_p = (UT_hash_handle*)((_hs_p->next) ? \
  729. ((void*)((char*)(_hs_p->next) + \
  730. (head)->hh.tbl->hho)) : NULL); \
  731. _hs_psize--; \
  732. } else if (( \
  733. cmpfcn(DECLTYPE(head)(ELMT_FROM_HH((head)->hh.tbl,_hs_p)), \
  734. DECLTYPE(head)(ELMT_FROM_HH((head)->hh.tbl,_hs_q))) \
  735. ) <= 0) { \
  736. _hs_e = _hs_p; \
  737. _hs_p = (UT_hash_handle*)((_hs_p->next) ? \
  738. ((void*)((char*)(_hs_p->next) + \
  739. (head)->hh.tbl->hho)) : NULL); \
  740. _hs_psize--; \
  741. } else { \
  742. _hs_e = _hs_q; \
  743. _hs_q = (UT_hash_handle*)((_hs_q->next) ? \
  744. ((void*)((char*)(_hs_q->next) + \
  745. (head)->hh.tbl->hho)) : NULL); \
  746. _hs_qsize--; \
  747. } \
  748. if ( _hs_tail ) { \
  749. _hs_tail->next = ((_hs_e) ? \
  750. ELMT_FROM_HH((head)->hh.tbl,_hs_e) : NULL); \
  751. } else { \
  752. _hs_list = _hs_e; \
  753. } \
  754. _hs_e->prev = ((_hs_tail) ? \
  755. ELMT_FROM_HH((head)->hh.tbl,_hs_tail) : NULL); \
  756. _hs_tail = _hs_e; \
  757. } \
  758. _hs_p = _hs_q; \
  759. } \
  760. _hs_tail->next = NULL; \
  761. if ( _hs_nmerges <= 1 ) { \
  762. _hs_looping=0; \
  763. (head)->hh.tbl->tail = _hs_tail; \
  764. DECLTYPE_ASSIGN(head,ELMT_FROM_HH((head)->hh.tbl, _hs_list)); \
  765. } \
  766. _hs_insize *= 2; \
  767. } \
  768. HASH_FSCK(hh,head); \
  769. } \
  770. } while (0)
  771. /* This function selects items from one hash into another hash.
  772. * The end result is that the selected items have dual presence
  773. * in both hashes. There is no copy of the items made; rather
  774. * they are added into the new hash through a secondary hash
  775. * hash handle that must be present in the structure. */
  776. #define HASH_SELECT(hh_dst, dst, hh_src, src, cond) \
  777. do { \
  778. unsigned _src_bkt, _dst_bkt; \
  779. void *_last_elt=NULL, *_elt; \
  780. UT_hash_handle *_src_hh, *_dst_hh, *_last_elt_hh=NULL; \
  781. ptrdiff_t _dst_hho = ((char*)(&(dst)->hh_dst) - (char*)(dst)); \
  782. if (src) { \
  783. for(_src_bkt=0; _src_bkt < (src)->hh_src.tbl->num_buckets; _src_bkt++) { \
  784. for(_src_hh = (src)->hh_src.tbl->buckets[_src_bkt].hh_head; \
  785. _src_hh; \
  786. _src_hh = _src_hh->hh_next) { \
  787. _elt = ELMT_FROM_HH((src)->hh_src.tbl, _src_hh); \
  788. if (cond(_elt)) { \
  789. _dst_hh = (UT_hash_handle*)(((char*)_elt) + _dst_hho); \
  790. _dst_hh->key = _src_hh->key; \
  791. _dst_hh->keylen = _src_hh->keylen; \
  792. _dst_hh->hashv = _src_hh->hashv; \
  793. _dst_hh->prev = _last_elt; \
  794. _dst_hh->next = NULL; \
  795. if (_last_elt_hh) { _last_elt_hh->next = _elt; } \
  796. if (!dst) { \
  797. DECLTYPE_ASSIGN(dst,_elt); \
  798. HASH_MAKE_TABLE(hh_dst,dst); \
  799. } else { \
  800. _dst_hh->tbl = (dst)->hh_dst.tbl; \
  801. } \
  802. HASH_TO_BKT(_dst_hh->hashv, _dst_hh->tbl->num_buckets, _dst_bkt); \
  803. HASH_ADD_TO_BKT(_dst_hh->tbl->buckets[_dst_bkt],_dst_hh); \
  804. (dst)->hh_dst.tbl->num_items++; \
  805. _last_elt = _elt; \
  806. _last_elt_hh = _dst_hh; \
  807. } \
  808. } \
  809. } \
  810. } \
  811. HASH_FSCK(hh_dst,dst); \
  812. } while (0)
  813. #define HASH_CLEAR(hh,head) \
  814. do { \
  815. if (head) { \
  816. uthash_free((head)->hh.tbl->buckets ); \
  817. uthash_free((head)->hh.tbl); \
  818. (head)=NULL; \
  819. } \
  820. } while(0)
  821. /* obtain a count of items in the hash */
  822. #define HASH_COUNT(head) HASH_CNT(hh,head)
  823. #define HASH_CNT(hh,head) (head?(head->hh.tbl->num_items):0)
  824. typedef struct UT_hash_bucket {
  825. struct UT_hash_handle *hh_head;
  826. unsigned count;
  827. /* expand_mult is normally set to 0. In this situation, the max chain length
  828. * threshold is enforced at its default value, HASH_BKT_CAPACITY_THRESH. (If
  829. * the bucket's chain exceeds this length, bucket expansion is triggered).
  830. * However, setting expand_mult to a non-zero value delays bucket expansion
  831. * (that would be triggered by additions to this particular bucket)
  832. * until its chain length reaches a *multiple* of HASH_BKT_CAPACITY_THRESH.
  833. * (The multiplier is simply expand_mult+1). The whole idea of this
  834. * multiplier is to reduce bucket expansions, since they are expensive, in
  835. * situations where we know that a particular bucket tends to be overused.
  836. * It is better to let its chain length grow to a longer yet-still-bounded
  837. * value, than to do an O(n) bucket expansion too often.
  838. */
  839. unsigned expand_mult;
  840. } UT_hash_bucket;
  841. /* random signature used only to find hash tables in external analysis */
  842. #define HASH_SIGNATURE 0xa0111fe1
  843. #define HASH_BLOOM_SIGNATURE 0xb12220f2
  844. typedef struct UT_hash_table {
  845. UT_hash_bucket *buckets;
  846. unsigned num_buckets, log2_num_buckets;
  847. unsigned num_items;
  848. struct UT_hash_handle *tail; /* tail hh in app order, for fast append */
  849. ptrdiff_t hho; /* hash handle offset (byte pos of hash handle in element */
  850. /* in an ideal situation (all buckets used equally), no bucket would have
  851. * more than ceil(#items/#buckets) items. that's the ideal chain length. */
  852. unsigned ideal_chain_maxlen;
  853. /* nonideal_items is the number of items in the hash whose chain position
  854. * exceeds the ideal chain maxlen. these items pay the penalty for an uneven
  855. * hash distribution; reaching them in a chain traversal takes >ideal steps */
  856. unsigned nonideal_items;
  857. /* ineffective expands occur when a bucket doubling was performed, but
  858. * afterward, more than half the items in the hash had nonideal chain
  859. * positions. If this happens on two consecutive expansions we inhibit any
  860. * further expansion, as it's not helping; this happens when the hash
  861. * function isn't a good fit for the key domain. When expansion is inhibited
  862. * the hash will still work, albeit no longer in constant time. */
  863. unsigned ineff_expands, noexpand;
  864. uint32_t signature; /* used only to find hash tables in external analysis */
  865. #ifdef HASH_BLOOM
  866. uint32_t bloom_sig; /* used only to test bloom exists in external analysis */
  867. uint8_t *bloom_bv;
  868. char bloom_nbits;
  869. #endif
  870. } UT_hash_table;
  871. typedef struct UT_hash_handle {
  872. struct UT_hash_table *tbl;
  873. void *prev; /* prev element in app order */
  874. void *next; /* next element in app order */
  875. struct UT_hash_handle *hh_prev; /* previous hh in bucket order */
  876. struct UT_hash_handle *hh_next; /* next hh in bucket order */
  877. void *key; /* ptr to enclosing struct's key */
  878. unsigned keylen; /* enclosing struct's key len */
  879. unsigned hashv; /* result of hash-fcn(key) */
  880. } UT_hash_handle;
  881. #endif /* UTHASH_H */