VirtualBox

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

Last change on this file since 67149 was 11551, checked in by vboxsync, 16 years ago

API/xpcom: prefix any C symbols in VBoxXPCOM.so, to avoid namespace pollution. Enabled only on Linux at the moment.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.3 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);
72
73#if defined(XP_OS2_VACPP) && defined(VACPP_FLIP) /* for nsSpaceManager.cpp */
74PR_END_EXTERN_C /* and nsHTMLDocument.cpp */
75#endif
76typedef PRIntn (PR_CALLBACK *PLHashEnumerator)(PLHashEntry *he, PRIntn i, void *arg);
77
78#if defined(XP_OS2_VACPP) && defined(VACPP_FLIP)
79PR_BEGIN_EXTERN_C
80#endif
81
82/* Flag bits in PLHashEnumerator's return value */
83#define HT_ENUMERATE_NEXT 0 /* continue enumerating entries */
84#define HT_ENUMERATE_STOP 1 /* stop enumerating entries */
85#define HT_ENUMERATE_REMOVE 2 /* remove and free the current entry */
86#define HT_ENUMERATE_UNHASH 4 /* just unhash the current entry */
87
88typedef struct PLHashAllocOps {
89 void * (PR_CALLBACK *allocTable)(void *pool, PRSize size);
90 void (PR_CALLBACK *freeTable)(void *pool, void *item);
91 PLHashEntry * (PR_CALLBACK *allocEntry)(void *pool, const void *key);
92 void (PR_CALLBACK *freeEntry)(void *pool, PLHashEntry *he, PRUintn flag);
93} PLHashAllocOps;
94
95#define HT_FREE_VALUE 0 /* just free the entry's value */
96#define HT_FREE_ENTRY 1 /* free value and entire entry */
97
98struct PLHashEntry {
99 PLHashEntry *next; /* hash chain linkage */
100 PLHashNumber keyHash; /* key hash function result */
101 const void *key; /* ptr to opaque key */
102 void *value; /* ptr to opaque value */
103};
104
105struct PLHashTable {
106 PLHashEntry **buckets; /* vector of hash buckets */
107 PRUint32 nentries; /* number of entries in table */
108 PRUint32 shift; /* multiplicative hash shift */
109 PLHashFunction keyHash; /* key hash function */
110 PLHashComparator keyCompare; /* key comparison function */
111 PLHashComparator valueCompare; /* value comparison function */
112 const PLHashAllocOps *allocOps; /* allocation operations */
113 void *allocPriv; /* allocation private data */
114#ifdef HASHMETER
115 PRUint32 nlookups; /* total number of lookups */
116 PRUint32 nsteps; /* number of hash chains traversed */
117 PRUint32 ngrows; /* number of table expansions */
118 PRUint32 nshrinks; /* number of table contractions */
119#endif
120};
121
122/*
123 * Create a new hash table.
124 * If allocOps is null, use default allocator ops built on top of malloc().
125 */
126PR_EXTERN(PLHashTable *)
127PL_NewHashTable(PRUint32 numBuckets, PLHashFunction keyHash,
128 PLHashComparator keyCompare, PLHashComparator valueCompare,
129 const PLHashAllocOps *allocOps, void *allocPriv);
130
131PR_EXTERN(void)
132PL_HashTableDestroy(PLHashTable *ht);
133
134/* Higher level access methods */
135PR_EXTERN(PLHashEntry *)
136PL_HashTableAdd(PLHashTable *ht, const void *key, void *value);
137
138PR_EXTERN(PRBool)
139PL_HashTableRemove(PLHashTable *ht, const void *key);
140
141PR_EXTERN(void *)
142PL_HashTableLookup(PLHashTable *ht, const void *key);
143
144PR_EXTERN(void *)
145PL_HashTableLookupConst(PLHashTable *ht, const void *key);
146
147PR_EXTERN(PRIntn)
148PL_HashTableEnumerateEntries(PLHashTable *ht, PLHashEnumerator f, void *arg);
149
150/* General-purpose C string hash function. */
151PR_EXTERN(PLHashNumber)
152PL_HashString(const void *key);
153
154/* Compare strings using strcmp(), return true if equal. */
155PR_EXTERN(PRIntn)
156PL_CompareStrings(const void *v1, const void *v2);
157
158/* Stub function just returns v1 == v2 */
159PR_EXTERN(PRIntn)
160PL_CompareValues(const void *v1, const void *v2);
161
162/* Low level access methods */
163PR_EXTERN(PLHashEntry **)
164PL_HashTableRawLookup(PLHashTable *ht, PLHashNumber keyHash, const void *key);
165
166PR_EXTERN(PLHashEntry **)
167PL_HashTableRawLookupConst(PLHashTable *ht, PLHashNumber keyHash,
168 const void *key);
169
170PR_EXTERN(PLHashEntry *)
171PL_HashTableRawAdd(PLHashTable *ht, PLHashEntry **hep, PLHashNumber keyHash,
172 const void *key, void *value);
173
174PR_EXTERN(void)
175PL_HashTableRawRemove(PLHashTable *ht, PLHashEntry **hep, PLHashEntry *he);
176
177/* This can be trivially implemented using PL_HashTableEnumerateEntries. */
178PR_EXTERN(PRIntn)
179PL_HashTableDump(PLHashTable *ht, PLHashEnumerator dump, FILE *fp);
180
181PR_END_EXTERN_C
182
183#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