VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/nsprpub/lib/ds/plhash.h

Last change on this file was 101869, checked in by vboxsync, 15 months ago

libs/xpcom: Remove code for unused platforms from nsprpub, bugref:10545

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.8 KB
Line 
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2/* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is the Netscape Portable Runtime (NSPR).
16 *
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998-2000
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 *
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
35 *
36 * ***** END LICENSE BLOCK ***** */
37
38#ifndef plhash_h___
39#define plhash_h___
40/*
41 * API to portable hash table code.
42 */
43#include <stdio.h>
44#include "prtypes.h"
45
46#ifdef VBOX_WITH_XPCOM_NAMESPACE_CLEANUP
47#define PL_CompareStrings VBoxNsplPL_CompareStrings
48#define PL_CompareValues VBoxNsplPL_CompareValues
49#define PL_HashString VBoxNsplPL_HashString
50#define PL_HashTableAdd VBoxNsplPL_HashTableAdd
51#define PL_HashTableDestroy VBoxNsplPL_HashTableDestroy
52#define PL_HashTableLookup VBoxNsplPL_HashTableLookup
53#define PL_HashTableRemove VBoxNsplPL_HashTableRemove
54#define PL_NewHashTable VBoxNsplPL_NewHashTable
55#define PL_HashTableDump VBoxNsplPL_HashTableDump
56#define PL_HashTableEnumerateEntries VBoxNsplPL_HashTableEnumerateEntries
57#define PL_HashTableLookupConst VBoxNsplPL_HashTableLookupConst
58#define PL_HashTableRawAdd VBoxNsplPL_HashTableRawAdd
59#define PL_HashTableRawLookup VBoxNsplPL_HashTableRawLookup
60#define PL_HashTableRawLookupConst VBoxNsplPL_HashTableRawLookupConst
61#define PL_HashTableRawRemove VBoxNsplPL_HashTableRawRemove
62#endif /* VBOX_WITH_XPCOM_NAMESPACE_CLEANUP */
63
64PR_BEGIN_EXTERN_C
65
66typedef struct PLHashEntry PLHashEntry;
67typedef struct PLHashTable PLHashTable;
68typedef PRUint32 PLHashNumber;
69#define PL_HASH_BITS 32 /* Number of bits in PLHashNumber */
70typedef PLHashNumber (PR_CALLBACK *PLHashFunction)(const void *key);
71typedef PRIntn (PR_CALLBACK *PLHashComparator)(const void *v1, const void *v2);
72typedef PRIntn (PR_CALLBACK *PLHashEnumerator)(PLHashEntry *he, PRIntn i, void *arg);
73
74/* Flag bits in PLHashEnumerator's return value */
75#define HT_ENUMERATE_NEXT 0 /* continue enumerating entries */
76#define HT_ENUMERATE_STOP 1 /* stop enumerating entries */
77#define HT_ENUMERATE_REMOVE 2 /* remove and free the current entry */
78#define HT_ENUMERATE_UNHASH 4 /* just unhash the current entry */
79
80typedef struct PLHashAllocOps {
81 void * (PR_CALLBACK *allocTable)(void *pool, PRSize size);
82 void (PR_CALLBACK *freeTable)(void *pool, void *item);
83 PLHashEntry * (PR_CALLBACK *allocEntry)(void *pool, const void *key);
84 void (PR_CALLBACK *freeEntry)(void *pool, PLHashEntry *he, PRUintn flag);
85} PLHashAllocOps;
86
87#define HT_FREE_VALUE 0 /* just free the entry's value */
88#define HT_FREE_ENTRY 1 /* free value and entire entry */
89
90struct PLHashEntry {
91 PLHashEntry *next; /* hash chain linkage */
92 PLHashNumber keyHash; /* key hash function result */
93 const void *key; /* ptr to opaque key */
94 void *value; /* ptr to opaque value */
95};
96
97struct PLHashTable {
98 PLHashEntry **buckets; /* vector of hash buckets */
99 PRUint32 nentries; /* number of entries in table */
100 PRUint32 shift; /* multiplicative hash shift */
101 PLHashFunction keyHash; /* key hash function */
102 PLHashComparator keyCompare; /* key comparison function */
103 PLHashComparator valueCompare; /* value comparison function */
104 const PLHashAllocOps *allocOps; /* allocation operations */
105 void *allocPriv; /* allocation private data */
106};
107
108/*
109 * Create a new hash table.
110 * If allocOps is null, use default allocator ops built on top of malloc().
111 */
112PR_EXTERN(PLHashTable *)
113PL_NewHashTable(PRUint32 numBuckets, PLHashFunction keyHash,
114 PLHashComparator keyCompare, PLHashComparator valueCompare,
115 const PLHashAllocOps *allocOps, void *allocPriv);
116
117PR_EXTERN(void)
118PL_HashTableDestroy(PLHashTable *ht);
119
120/* Higher level access methods */
121PR_EXTERN(PLHashEntry *)
122PL_HashTableAdd(PLHashTable *ht, const void *key, void *value);
123
124PR_EXTERN(PRBool)
125PL_HashTableRemove(PLHashTable *ht, const void *key);
126
127PR_EXTERN(void *)
128PL_HashTableLookup(PLHashTable *ht, const void *key);
129
130PR_EXTERN(void *)
131PL_HashTableLookupConst(PLHashTable *ht, const void *key);
132
133PR_EXTERN(PRIntn)
134PL_HashTableEnumerateEntries(PLHashTable *ht, PLHashEnumerator f, void *arg);
135
136/* General-purpose C string hash function. */
137PR_EXTERN(PLHashNumber)
138PL_HashString(const void *key);
139
140/* Compare strings using strcmp(), return true if equal. */
141PR_EXTERN(PRIntn)
142PL_CompareStrings(const void *v1, const void *v2);
143
144/* Stub function just returns v1 == v2 */
145PR_EXTERN(PRIntn)
146PL_CompareValues(const void *v1, const void *v2);
147
148/* Low level access methods */
149PR_EXTERN(PLHashEntry **)
150PL_HashTableRawLookup(PLHashTable *ht, PLHashNumber keyHash, const void *key);
151
152PR_EXTERN(PLHashEntry **)
153PL_HashTableRawLookupConst(PLHashTable *ht, PLHashNumber keyHash,
154 const void *key);
155
156PR_EXTERN(PLHashEntry *)
157PL_HashTableRawAdd(PLHashTable *ht, PLHashEntry **hep, PLHashNumber keyHash,
158 const void *key, void *value);
159
160PR_EXTERN(void)
161PL_HashTableRawRemove(PLHashTable *ht, PLHashEntry **hep, PLHashEntry *he);
162
163/* This can be trivially implemented using PL_HashTableEnumerateEntries. */
164PR_EXTERN(PRIntn)
165PL_HashTableDump(PLHashTable *ht, PLHashEnumerator dump, FILE *fp);
166
167PR_END_EXTERN_C
168
169#endif /* plhash_h___ */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette