PageRenderTime 93ms CodeModel.GetById 40ms app.highlight 10ms RepoModel.GetById 40ms app.codeStats 1ms

/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
  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
 40#ifndef jshash_h___
 41#define jshash_h___
 42/*
 43 * API to portable hash table code.
 44 */
 45#include <stddef.h>
 46#include <stdio.h>
 47#include "jstypes.h"
 48#include "jscompat.h"
 49
 50JS_BEGIN_EXTERN_C
 51
 52typedef uint32 JSHashNumber;
 53typedef struct JSHashEntry JSHashEntry;
 54typedef struct JSHashTable JSHashTable;
 55
 56#define JS_HASH_BITS 32
 57#define JS_GOLDEN_RATIO 0x9E3779B9U
 58
 59typedef JSHashNumber (* JSHashFunction)(const void *key);
 60typedef intN (* JSHashComparator)(const void *v1, const void *v2);
 61typedef intN (* JSHashEnumerator)(JSHashEntry *he, intN i, void *arg);
 62
 63/* Flag bits in JSHashEnumerator's return value */
 64#define HT_ENUMERATE_NEXT       0       /* continue enumerating entries */
 65#define HT_ENUMERATE_STOP       1       /* stop enumerating entries */
 66#define HT_ENUMERATE_REMOVE     2       /* remove and free the current entry */
 67
 68typedef struct JSHashAllocOps {
 69    void *              (*allocTable)(void *pool, size_t size);
 70    void                (*freeTable)(void *pool, void *item);
 71    JSHashEntry *       (*allocEntry)(void *pool, const void *key);
 72    void                (*freeEntry)(void *pool, JSHashEntry *he, uintN flag);
 73} JSHashAllocOps;
 74
 75#define HT_FREE_VALUE   0               /* just free the entry's value */
 76#define HT_FREE_ENTRY   1               /* free value and entire entry */
 77
 78struct JSHashEntry {
 79    JSHashEntry         *next;          /* hash chain linkage */
 80    JSHashNumber        keyHash;        /* key hash function result */
 81    const void          *key;           /* ptr to opaque key */
 82    void                *value;         /* ptr to opaque value */
 83};
 84
 85struct JSHashTable {
 86    JSHashEntry         **buckets;      /* vector of hash buckets */
 87    uint32              nentries;       /* number of entries in table */
 88    uint32              shift;          /* multiplicative hash shift */
 89    JSHashFunction      keyHash;        /* key hash function */
 90    JSHashComparator    keyCompare;     /* key comparison function */
 91    JSHashComparator    valueCompare;   /* value comparison function */
 92    JSHashAllocOps      *allocOps;      /* allocation operations */
 93    void                *allocPriv;     /* allocation private data */
 94#ifdef JS_HASHMETER
 95    uint32              nlookups;       /* total number of lookups */
 96    uint32              nsteps;         /* number of hash chains traversed */
 97    uint32              ngrows;         /* number of table expansions */
 98    uint32              nshrinks;       /* number of table contractions */
 99#endif
100};
101
102/*
103 * Create a new hash table.
104 * If allocOps is null, use default allocator ops built on top of malloc().
105 */
106extern JS_PUBLIC_API(JSHashTable *)
107JS_NewHashTable(uint32 n, JSHashFunction keyHash,
108                JSHashComparator keyCompare, JSHashComparator valueCompare,
109                JSHashAllocOps *allocOps, void *allocPriv);
110
111extern JS_PUBLIC_API(void)
112JS_HashTableDestroy(JSHashTable *ht);
113
114/* Low level access methods */
115extern JS_PUBLIC_API(JSHashEntry **)
116JS_HashTableRawLookup(JSHashTable *ht, JSHashNumber keyHash, const void *key);
117
118extern JS_PUBLIC_API(JSHashEntry *)
119JS_HashTableRawAdd(JSHashTable *ht, JSHashEntry **hep, JSHashNumber keyHash,
120                   const void *key, void *value);
121
122extern JS_PUBLIC_API(void)
123JS_HashTableRawRemove(JSHashTable *ht, JSHashEntry **hep, JSHashEntry *he);
124
125/* Higher level access methods */
126extern JS_PUBLIC_API(JSHashEntry *)
127JS_HashTableAdd(JSHashTable *ht, const void *key, void *value);
128
129extern JS_PUBLIC_API(JSBool)
130JS_HashTableRemove(JSHashTable *ht, const void *key);
131
132extern JS_PUBLIC_API(intN)
133JS_HashTableEnumerateEntries(JSHashTable *ht, JSHashEnumerator f, void *arg);
134
135extern JS_PUBLIC_API(void *)
136JS_HashTableLookup(JSHashTable *ht, const void *key);
137
138extern JS_PUBLIC_API(intN)
139JS_HashTableDump(JSHashTable *ht, JSHashEnumerator dump, FILE *fp);
140
141/* General-purpose C string hash function. */
142extern JS_PUBLIC_API(JSHashNumber)
143JS_HashString(const void *key);
144
145/* Stub function just returns v1 == v2 */
146extern JS_PUBLIC_API(intN)
147JS_CompareValues(const void *v1, const void *v2);
148
149JS_END_EXTERN_C
150
151#endif /* jshash_h___ */