2 * The contents of this file are subject to the Mozilla Public
3 * License Version 1.1 (the "License"); you may not use this file
4 * except in compliance with the License. You may obtain a copy of
5 * the License at http://www.mozilla.org/MPL/
7 * Software distributed under the License is distributed on an "AS
8 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9 * implied. See the License for the specific language governing
10 * rights and limitations under the License.
12 * The Original Code is the Sablotron XSLT Processor.
14 * The Initial Developer of the Original Code is Ginger Alliance Ltd.
15 * Portions created by Ginger Alliance are Copyright (C) 2000-2002
16 * Ginger Alliance Ltd. All Rights Reserved.
19 * Bob Jenkins <bob_jenkins@burtleburtle.net>
21 * Alternatively, the contents of this file may be used under the
22 * terms of the GNU General Public License Version 2 or later (the
23 * "GPL"), in which case the provisions of the GPL are applicable
24 * instead of those above. If you wish to allow use of your
25 * version of this file only under the terms of the GPL and not to
26 * allow others to use your version of this file under the MPL,
27 * indicate your decision by deleting the provisions above and
28 * replace them with the notice and other provisions required by
29 * the GPL. If you do not delete the provisions above, a recipient
30 * may use your version of this file under either the MPL or the
35 * based on hash function and code by Bob Jenkins, <bob_jenkins@burtleburtle.net>, 1996.
38 #if !defined(HashHIncl)
52 // an item in the hash table. Contains part of the unique ID, the key and associated stuff (a void*).
55 class HashItem : public SabArenaMember
58 HashItem(const char *key_, oolong code_, const void *stuff_, int age_, SabArena *arena_)
59 : key( (char*)key_, arena_ ), code( code_ ), stuff( stuff_ ),
60 age( age_ ), next( NULL )
62 const SabArenaStr key;
71 // used for the list of buckets
74 class HashItemList : public PList<HashItem*>
76 friend class HashTable;
77 HashItemList( int logSize_ )
78 : PList<HashItem*>( logSize_ )
84 // Simple hash table. It can grow, the items have a unique ID which allows quick lookup
85 // of the key as well as the associated value.
91 // initialize the hash
92 HashTable(SabArena *arena_, int logSize_);
97 // insert an item, returning its id (if found as well as if not)
98 void insert(const Str& key, HashId& id, const void *data = NULL );
100 void insert(const char *key, HashId& id, const void *data = NULL )
102 insert(Str(key), id, data);
105 HashId insert(const Str& key);
107 HashId insert(const char *key, const void *data = NULL )
109 return insert(Str(key));
114 // look up an item, returning ITEM_NOT_FOUND and data==NULL if not found
115 HashId lookup(const Str& key, const void **data = NULL ) const;
117 // return the key for a given id, asserting it exists
118 const Str& getKey(HashId id) const;
128 oolong codeToIndex(oolong code) const;
129 HashItem* expandWatching(oolong hashed);
130 Bool lookupOrPreceding(const Str& key, oolong hashed, HashItem *&p) const;
131 HashItemList buckets; // the list of buckets
132 SabArena *theArena; // the arena to be used for hash items
137 void report(Sit S, MsgType type, MsgCode code, const Str& arg1, const Str& arg2);
139 Str *_theEmptyKey; /* __PH__ */