PageRenderTime 50ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/js/lib/Socket.IO-node/support/expresso/deps/jscoverage/js/jshash.h

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
C++ Header | 151 lines | 77 code | 24 blank | 50 comment | 0 complexity | 4524ee744f7d6bb8697115708dcb5b2f MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  2. *
  3. * ***** BEGIN LICENSE BLOCK *****
  4. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  5. *
  6. * The contents of this file are subject to the Mozilla Public License Version
  7. * 1.1 (the "License"); you may not use this file except in compliance with
  8. * the License. You may obtain a copy of the License at
  9. * http://www.mozilla.org/MPL/
  10. *
  11. * Software distributed under the License is distributed on an "AS IS" basis,
  12. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  13. * for the specific language governing rights and limitations under the
  14. * License.
  15. *
  16. * The Original Code is Mozilla Communicator client code, released
  17. * March 31, 1998.
  18. *
  19. * The Initial Developer of the Original Code is
  20. * Netscape Communications Corporation.
  21. * Portions created by the Initial Developer are Copyright (C) 1998
  22. * the Initial Developer. All Rights Reserved.
  23. *
  24. * Contributor(s):
  25. *
  26. * Alternatively, the contents of this file may be used under the terms of
  27. * either of the GNU General Public License Version 2 or later (the "GPL"),
  28. * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  29. * in which case the provisions of the GPL or the LGPL are applicable instead
  30. * of those above. If you wish to allow use of your version of this file only
  31. * under the terms of either the GPL or the LGPL, and not to allow others to
  32. * use your version of this file under the terms of the MPL, indicate your
  33. * decision by deleting the provisions above and replace them with the notice
  34. * and other provisions required by the GPL or the LGPL. If you do not delete
  35. * the provisions above, a recipient may use your version of this file under
  36. * the terms of any one of the MPL, the GPL or the LGPL.
  37. *
  38. * ***** END LICENSE BLOCK ***** */
  39. #ifndef jshash_h___
  40. #define jshash_h___
  41. /*
  42. * API to portable hash table code.
  43. */
  44. #include <stddef.h>
  45. #include <stdio.h>
  46. #include "jstypes.h"
  47. #include "jscompat.h"
  48. JS_BEGIN_EXTERN_C
  49. typedef uint32 JSHashNumber;
  50. typedef struct JSHashEntry JSHashEntry;
  51. typedef struct JSHashTable JSHashTable;
  52. #define JS_HASH_BITS 32
  53. #define JS_GOLDEN_RATIO 0x9E3779B9U
  54. typedef JSHashNumber (* JSHashFunction)(const void *key);
  55. typedef intN (* JSHashComparator)(const void *v1, const void *v2);
  56. typedef intN (* JSHashEnumerator)(JSHashEntry *he, intN i, void *arg);
  57. /* Flag bits in JSHashEnumerator's return value */
  58. #define HT_ENUMERATE_NEXT 0 /* continue enumerating entries */
  59. #define HT_ENUMERATE_STOP 1 /* stop enumerating entries */
  60. #define HT_ENUMERATE_REMOVE 2 /* remove and free the current entry */
  61. typedef struct JSHashAllocOps {
  62. void * (*allocTable)(void *pool, size_t size);
  63. void (*freeTable)(void *pool, void *item);
  64. JSHashEntry * (*allocEntry)(void *pool, const void *key);
  65. void (*freeEntry)(void *pool, JSHashEntry *he, uintN flag);
  66. } JSHashAllocOps;
  67. #define HT_FREE_VALUE 0 /* just free the entry's value */
  68. #define HT_FREE_ENTRY 1 /* free value and entire entry */
  69. struct JSHashEntry {
  70. JSHashEntry *next; /* hash chain linkage */
  71. JSHashNumber keyHash; /* key hash function result */
  72. const void *key; /* ptr to opaque key */
  73. void *value; /* ptr to opaque value */
  74. };
  75. struct JSHashTable {
  76. JSHashEntry **buckets; /* vector of hash buckets */
  77. uint32 nentries; /* number of entries in table */
  78. uint32 shift; /* multiplicative hash shift */
  79. JSHashFunction keyHash; /* key hash function */
  80. JSHashComparator keyCompare; /* key comparison function */
  81. JSHashComparator valueCompare; /* value comparison function */
  82. JSHashAllocOps *allocOps; /* allocation operations */
  83. void *allocPriv; /* allocation private data */
  84. #ifdef JS_HASHMETER
  85. uint32 nlookups; /* total number of lookups */
  86. uint32 nsteps; /* number of hash chains traversed */
  87. uint32 ngrows; /* number of table expansions */
  88. uint32 nshrinks; /* number of table contractions */
  89. #endif
  90. };
  91. /*
  92. * Create a new hash table.
  93. * If allocOps is null, use default allocator ops built on top of malloc().
  94. */
  95. extern JS_PUBLIC_API(JSHashTable *)
  96. JS_NewHashTable(uint32 n, JSHashFunction keyHash,
  97. JSHashComparator keyCompare, JSHashComparator valueCompare,
  98. JSHashAllocOps *allocOps, void *allocPriv);
  99. extern JS_PUBLIC_API(void)
  100. JS_HashTableDestroy(JSHashTable *ht);
  101. /* Low level access methods */
  102. extern JS_PUBLIC_API(JSHashEntry **)
  103. JS_HashTableRawLookup(JSHashTable *ht, JSHashNumber keyHash, const void *key);
  104. extern JS_PUBLIC_API(JSHashEntry *)
  105. JS_HashTableRawAdd(JSHashTable *ht, JSHashEntry **hep, JSHashNumber keyHash,
  106. const void *key, void *value);
  107. extern JS_PUBLIC_API(void)
  108. JS_HashTableRawRemove(JSHashTable *ht, JSHashEntry **hep, JSHashEntry *he);
  109. /* Higher level access methods */
  110. extern JS_PUBLIC_API(JSHashEntry *)
  111. JS_HashTableAdd(JSHashTable *ht, const void *key, void *value);
  112. extern JS_PUBLIC_API(JSBool)
  113. JS_HashTableRemove(JSHashTable *ht, const void *key);
  114. extern JS_PUBLIC_API(intN)
  115. JS_HashTableEnumerateEntries(JSHashTable *ht, JSHashEnumerator f, void *arg);
  116. extern JS_PUBLIC_API(void *)
  117. JS_HashTableLookup(JSHashTable *ht, const void *key);
  118. extern JS_PUBLIC_API(intN)
  119. JS_HashTableDump(JSHashTable *ht, JSHashEnumerator dump, FILE *fp);
  120. /* General-purpose C string hash function. */
  121. extern JS_PUBLIC_API(JSHashNumber)
  122. JS_HashString(const void *key);
  123. /* Stub function just returns v1 == v2 */
  124. extern JS_PUBLIC_API(intN)
  125. JS_CompareValues(const void *v1, const void *v2);
  126. JS_END_EXTERN_C
  127. #endif /* jshash_h___ */