[188] | 1 | /*
|
---|
| 2 | * The Apache Software License, Version 1.1
|
---|
| 3 | *
|
---|
| 4 | * Copyright (c) 2001-2003 The Apache Software Foundation. All rights
|
---|
| 5 | * reserved.
|
---|
| 6 | *
|
---|
| 7 | * Redistribution and use in source and binary forms, with or without
|
---|
| 8 | * modification, are permitted provided that the following conditions
|
---|
| 9 | * are met:
|
---|
| 10 | *
|
---|
| 11 | * 1. Redistributions of source code must retain the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer.
|
---|
| 13 | *
|
---|
| 14 | * 2. Redistributions in binary form must reproduce the above copyright
|
---|
| 15 | * notice, this list of conditions and the following disclaimer in
|
---|
| 16 | * the documentation and/or other materials provided with the
|
---|
| 17 | * distribution.
|
---|
| 18 | *
|
---|
| 19 | * 3. The end-user documentation included with the redistribution,
|
---|
| 20 | * if any, must include the following acknowledgment:
|
---|
| 21 | * "This product includes software developed by the
|
---|
| 22 | * Apache Software Foundation (http://www.apache.org/)."
|
---|
| 23 | * Alternately, this acknowledgment may appear in the software itself,
|
---|
| 24 | * if and wherever such third-party acknowledgments normally appear.
|
---|
| 25 | *
|
---|
| 26 | * 4. The names "Xerces" and "Apache Software Foundation" must
|
---|
| 27 | * not be used to endorse or promote products derived from this
|
---|
| 28 | * software without prior written permission. For written
|
---|
| 29 | * permission, please contact apache\@apache.org.
|
---|
| 30 | *
|
---|
| 31 | * 5. Products derived from this software may not be called "Apache",
|
---|
| 32 | * nor may "Apache" appear in their name, without prior written
|
---|
| 33 | * permission of the Apache Software Foundation.
|
---|
| 34 | *
|
---|
| 35 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
---|
| 36 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 37 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
---|
| 38 | * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
|
---|
| 39 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
---|
| 40 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
---|
| 41 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
---|
| 42 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
---|
| 43 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
---|
| 44 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
---|
| 45 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
---|
| 46 | * SUCH DAMAGE.
|
---|
| 47 | * ====================================================================
|
---|
| 48 | *
|
---|
| 49 | * This software consists of voluntary contributions made by many
|
---|
| 50 | * individuals on behalf of the Apache Software Foundation, and was
|
---|
| 51 | * originally based on software copyright (c) 2001, International
|
---|
| 52 | * Business Machines, Inc., http://www.ibm.com . For more information
|
---|
| 53 | * on the Apache Software Foundation, please see
|
---|
| 54 | * <http://www.apache.org/>.
|
---|
| 55 | */
|
---|
| 56 |
|
---|
| 57 | /*
|
---|
| 58 | * $Log: RefHash2KeysTableOf.hpp,v $
|
---|
| 59 | * Revision 1.9 2004/01/29 11:48:46 cargilld
|
---|
| 60 | * Code cleanup changes to get rid of various compiler diagnostic messages.
|
---|
| 61 | *
|
---|
| 62 | * Revision 1.8 2003/12/17 00:18:35 cargilld
|
---|
| 63 | * Update to memory management so that the static memory manager (one used to call Initialize) is only for static data.
|
---|
| 64 | *
|
---|
| 65 | * Revision 1.7 2003/10/20 11:45:06 gareth
|
---|
| 66 | * Made enumerators inherit from XMemory.
|
---|
| 67 | *
|
---|
| 68 | * Revision 1.6 2003/10/17 21:10:40 peiyongz
|
---|
| 69 | * nextElementKey() added
|
---|
| 70 | *
|
---|
| 71 | * Revision 1.5 2003/05/18 14:02:05 knoaman
|
---|
| 72 | * Memory manager implementation: pass per instance manager.
|
---|
| 73 | *
|
---|
| 74 | * Revision 1.4 2003/05/15 19:04:35 knoaman
|
---|
| 75 | * Partial implementation of the configurable memory manager.
|
---|
| 76 | *
|
---|
| 77 | * Revision 1.3 2002/11/04 15:22:04 tng
|
---|
| 78 | * C++ Namespace Support.
|
---|
| 79 | *
|
---|
| 80 | * Revision 1.2 2002/06/12 17:15:12 tng
|
---|
| 81 | * Remove redundant include header file.
|
---|
| 82 | *
|
---|
| 83 | * Revision 1.1.1.1 2002/02/01 22:22:12 peiyongz
|
---|
| 84 | * sane_include
|
---|
| 85 | *
|
---|
| 86 | * Revision 1.4 2001/12/22 01:06:08 jasons
|
---|
| 87 | * Made the destructors virtual for:
|
---|
| 88 | *
|
---|
| 89 | * * ~RefHash2KeysTableOfEnumerator
|
---|
| 90 | * * ~RefHash3KeysIdPoolEnumerator
|
---|
| 91 | *
|
---|
| 92 | * This fixes bug #5514
|
---|
| 93 | *
|
---|
| 94 | * Revision 1.3 2001/06/04 13:45:03 tng
|
---|
| 95 | * The "hash" argument clashes with STL hash. Fixed by Pei Yong Zhang.
|
---|
| 96 | *
|
---|
| 97 | * Revision 1.2 2001/05/11 13:26:28 tng
|
---|
| 98 | * Copyright update.
|
---|
| 99 | *
|
---|
| 100 | * Revision 1.1 2001/02/27 18:24:01 tng
|
---|
| 101 | * Schema: Add utility RefHash2KeysTableOf.
|
---|
| 102 | *
|
---|
| 103 | */
|
---|
| 104 |
|
---|
| 105 |
|
---|
| 106 | #if !defined(REFHASH2KEYSTABLEOF_HPP)
|
---|
| 107 | #define REFHASH2KEYSTABLEOF_HPP
|
---|
| 108 |
|
---|
| 109 |
|
---|
| 110 | #include <xercesc/util/HashBase.hpp>
|
---|
| 111 | #include <xercesc/util/IllegalArgumentException.hpp>
|
---|
| 112 | #include <xercesc/util/NoSuchElementException.hpp>
|
---|
| 113 | #include <xercesc/util/RuntimeException.hpp>
|
---|
| 114 | #include <xercesc/util/XMLString.hpp>
|
---|
| 115 | #include <xercesc/util/HashXMLCh.hpp>
|
---|
| 116 | #include <xercesc/util/PlatformUtils.hpp>
|
---|
| 117 |
|
---|
| 118 | XERCES_CPP_NAMESPACE_BEGIN
|
---|
| 119 |
|
---|
| 120 | // This hash table is similar to RefHashTableOf with an additional integer as key2
|
---|
| 121 |
|
---|
| 122 | //
|
---|
| 123 | // Forward declare the enumerator so he can be our friend. Can you say
|
---|
| 124 | // friend? Sure...
|
---|
| 125 | //
|
---|
| 126 | template <class TVal> class RefHash2KeysTableOfEnumerator;
|
---|
| 127 | template <class TVal> struct RefHash2KeysTableBucketElem;
|
---|
| 128 |
|
---|
| 129 |
|
---|
| 130 | //
|
---|
| 131 | // This should really be a nested class, but some of the compilers we
|
---|
| 132 | // have to support cannot deal with that!
|
---|
| 133 | //
|
---|
| 134 | template <class TVal> struct RefHash2KeysTableBucketElem : public XMemory
|
---|
| 135 | {
|
---|
| 136 | RefHash2KeysTableBucketElem(void* key1, int key2, TVal* const value, RefHash2KeysTableBucketElem<TVal>* next)
|
---|
| 137 | : fData(value), fNext(next), fKey1(key1), fKey2(key2)
|
---|
| 138 | {
|
---|
| 139 | }
|
---|
| 140 | ~RefHash2KeysTableBucketElem() {};
|
---|
| 141 |
|
---|
| 142 | TVal* fData;
|
---|
| 143 | RefHash2KeysTableBucketElem<TVal>* fNext;
|
---|
| 144 | void* fKey1;
|
---|
| 145 | int fKey2;
|
---|
| 146 |
|
---|
| 147 | private:
|
---|
| 148 | // -----------------------------------------------------------------------
|
---|
| 149 | // Unimplemented constructors and operators
|
---|
| 150 | // -----------------------------------------------------------------------
|
---|
| 151 | RefHash2KeysTableBucketElem(const RefHash2KeysTableBucketElem<TVal>&);
|
---|
| 152 | RefHash2KeysTableBucketElem<TVal>& operator=(const RefHash2KeysTableBucketElem<TVal>&);
|
---|
| 153 | };
|
---|
| 154 |
|
---|
| 155 |
|
---|
| 156 | template <class TVal> class RefHash2KeysTableOf : public XMemory
|
---|
| 157 | {
|
---|
| 158 | public:
|
---|
| 159 | // -----------------------------------------------------------------------
|
---|
| 160 | // Constructors and Destructor
|
---|
| 161 | // -----------------------------------------------------------------------
|
---|
| 162 | // backwards compatability - default hasher is HashXMLCh
|
---|
| 163 | RefHash2KeysTableOf
|
---|
| 164 | (
|
---|
| 165 | const unsigned int modulus
|
---|
| 166 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
---|
| 167 | );
|
---|
| 168 | // backwards compatability - default hasher is HashXMLCh
|
---|
| 169 | RefHash2KeysTableOf
|
---|
| 170 | (
|
---|
| 171 | const unsigned int modulus
|
---|
| 172 | , const bool adoptElems
|
---|
| 173 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
---|
| 174 | );
|
---|
| 175 | // if a hash function is passed in, it will be deleted when the hashtable is deleted.
|
---|
| 176 | // use a new instance of the hasher class for each hashtable, otherwise one hashtable
|
---|
| 177 | // may delete the hasher of a different hashtable if both use the same hasher.
|
---|
| 178 | RefHash2KeysTableOf
|
---|
| 179 | (
|
---|
| 180 | const unsigned int modulus
|
---|
| 181 | , const bool adoptElems
|
---|
| 182 | , HashBase* hashBase
|
---|
| 183 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
---|
| 184 | );
|
---|
| 185 | ~RefHash2KeysTableOf();
|
---|
| 186 |
|
---|
| 187 |
|
---|
| 188 | // -----------------------------------------------------------------------
|
---|
| 189 | // Element management
|
---|
| 190 | // -----------------------------------------------------------------------
|
---|
| 191 | bool isEmpty() const;
|
---|
| 192 | bool containsKey(const void* const key1, const int key2) const;
|
---|
| 193 | void removeKey(const void* const key1, const int key2);
|
---|
| 194 | void removeAll();
|
---|
| 195 |
|
---|
| 196 |
|
---|
| 197 | // -----------------------------------------------------------------------
|
---|
| 198 | // Getters
|
---|
| 199 | // -----------------------------------------------------------------------
|
---|
| 200 | TVal* get(const void* const key1, const int key2);
|
---|
| 201 | const TVal* get(const void* const key1, const int key2) const;
|
---|
| 202 |
|
---|
| 203 | MemoryManager* getMemoryManager() const;
|
---|
| 204 | // -----------------------------------------------------------------------
|
---|
| 205 | // Putters
|
---|
| 206 | // -----------------------------------------------------------------------
|
---|
| 207 | void put(void* key1, int key2, TVal* const valueToAdopt);
|
---|
| 208 |
|
---|
| 209 |
|
---|
| 210 | private :
|
---|
| 211 | // -----------------------------------------------------------------------
|
---|
| 212 | // Declare our friends
|
---|
| 213 | // -----------------------------------------------------------------------
|
---|
| 214 | friend class RefHash2KeysTableOfEnumerator<TVal>;
|
---|
| 215 |
|
---|
| 216 |
|
---|
| 217 | private:
|
---|
| 218 | // -----------------------------------------------------------------------
|
---|
| 219 | // Unimplemented constructors and operators
|
---|
| 220 | // -----------------------------------------------------------------------
|
---|
| 221 | RefHash2KeysTableOf(const RefHash2KeysTableOf<TVal>&);
|
---|
| 222 | RefHash2KeysTableOf<TVal>& operator=(const RefHash2KeysTableOf<TVal>&);
|
---|
| 223 |
|
---|
| 224 | // -----------------------------------------------------------------------
|
---|
| 225 | // Private methods
|
---|
| 226 | // -----------------------------------------------------------------------
|
---|
| 227 | RefHash2KeysTableBucketElem<TVal>* findBucketElem(const void* const key1, const int key2, unsigned int& hashVal);
|
---|
| 228 | const RefHash2KeysTableBucketElem<TVal>* findBucketElem(const void* const key1, const int key2, unsigned int& hashVal) const;
|
---|
| 229 | void removeBucketElem(const void* const key1, const int key2, unsigned int& hashVal);
|
---|
| 230 | void initialize(const unsigned int modulus);
|
---|
| 231 |
|
---|
| 232 |
|
---|
| 233 | // -----------------------------------------------------------------------
|
---|
| 234 | // Data members
|
---|
| 235 | //
|
---|
| 236 | // fAdoptedElems
|
---|
| 237 | // Indicates whether the values added are adopted or just referenced.
|
---|
| 238 | // If adopted, then they are deleted when they are removed from the
|
---|
| 239 | // hash table.
|
---|
| 240 | //
|
---|
| 241 | // fBucketList
|
---|
| 242 | // This is the array that contains the heads of all of the list
|
---|
| 243 | // buckets, one for each possible hash value.
|
---|
| 244 | //
|
---|
| 245 | // fHashModulus
|
---|
| 246 | // The modulus used for this hash table, to hash the keys. This is
|
---|
| 247 | // also the number of elements in the bucket list.
|
---|
| 248 | //
|
---|
| 249 | // fHash
|
---|
| 250 | // The hasher for the key1 data type.
|
---|
| 251 | // -----------------------------------------------------------------------
|
---|
| 252 | MemoryManager* fMemoryManager;
|
---|
| 253 | bool fAdoptedElems;
|
---|
| 254 | RefHash2KeysTableBucketElem<TVal>** fBucketList;
|
---|
| 255 | unsigned int fHashModulus;
|
---|
| 256 | HashBase* fHash;
|
---|
| 257 | };
|
---|
| 258 |
|
---|
| 259 |
|
---|
| 260 |
|
---|
| 261 | //
|
---|
| 262 | // An enumerator for a value array. It derives from the basic enumerator
|
---|
| 263 | // class, so that value vectors can be generically enumerated.
|
---|
| 264 | //
|
---|
| 265 | template <class TVal> class RefHash2KeysTableOfEnumerator : public XMLEnumerator<TVal>, public XMemory
|
---|
| 266 | {
|
---|
| 267 | public :
|
---|
| 268 | // -----------------------------------------------------------------------
|
---|
| 269 | // Constructors and Destructor
|
---|
| 270 | // -----------------------------------------------------------------------
|
---|
| 271 | RefHash2KeysTableOfEnumerator(RefHash2KeysTableOf<TVal>* const toEnum
|
---|
| 272 | , const bool adopt = false
|
---|
| 273 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
---|
| 274 | virtual ~RefHash2KeysTableOfEnumerator();
|
---|
| 275 |
|
---|
| 276 |
|
---|
| 277 | // -----------------------------------------------------------------------
|
---|
| 278 | // Enum interface
|
---|
| 279 | // -----------------------------------------------------------------------
|
---|
| 280 | bool hasMoreElements() const;
|
---|
| 281 | TVal& nextElement();
|
---|
| 282 | void Reset();
|
---|
| 283 |
|
---|
| 284 | // -----------------------------------------------------------------------
|
---|
| 285 | // New interface
|
---|
| 286 | // -----------------------------------------------------------------------
|
---|
| 287 | void nextElementKey(void*&, int&);
|
---|
| 288 |
|
---|
| 289 | private :
|
---|
| 290 | // -----------------------------------------------------------------------
|
---|
| 291 | // Unimplemented constructors and operators
|
---|
| 292 | // -----------------------------------------------------------------------
|
---|
| 293 | RefHash2KeysTableOfEnumerator(const RefHash2KeysTableOfEnumerator<TVal>&);
|
---|
| 294 | RefHash2KeysTableOfEnumerator<TVal>& operator=(const RefHash2KeysTableOfEnumerator<TVal>&);
|
---|
| 295 |
|
---|
| 296 | // -----------------------------------------------------------------------
|
---|
| 297 | // Private methods
|
---|
| 298 | // -----------------------------------------------------------------------
|
---|
| 299 | void findNext();
|
---|
| 300 |
|
---|
| 301 |
|
---|
| 302 | // -----------------------------------------------------------------------
|
---|
| 303 | // Data Members
|
---|
| 304 | //
|
---|
| 305 | // fAdopted
|
---|
| 306 | // Indicates whether we have adopted the passed vector. If so then
|
---|
| 307 | // we delete the vector when we are destroyed.
|
---|
| 308 | //
|
---|
| 309 | // fCurElem
|
---|
| 310 | // This is the current bucket bucket element that we are on.
|
---|
| 311 | //
|
---|
| 312 | // fCurHash
|
---|
| 313 | // The is the current hash buck that we are working on. Once we hit
|
---|
| 314 | // the end of the bucket that fCurElem is in, then we have to start
|
---|
| 315 | // working this one up to the next non-empty bucket.
|
---|
| 316 | //
|
---|
| 317 | // fToEnum
|
---|
| 318 | // The value array being enumerated.
|
---|
| 319 | // -----------------------------------------------------------------------
|
---|
| 320 | bool fAdopted;
|
---|
| 321 | RefHash2KeysTableBucketElem<TVal>* fCurElem;
|
---|
| 322 | unsigned int fCurHash;
|
---|
| 323 | RefHash2KeysTableOf<TVal>* fToEnum;
|
---|
| 324 | MemoryManager* const fMemoryManager;
|
---|
| 325 | };
|
---|
| 326 |
|
---|
| 327 | XERCES_CPP_NAMESPACE_END
|
---|
| 328 |
|
---|
| 329 | #if !defined(XERCES_TMPLSINC)
|
---|
| 330 | #include <xercesc/util/RefHash2KeysTableOf.c>
|
---|
| 331 | #endif
|
---|
| 332 |
|
---|
| 333 | #endif
|
---|