Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:15:12

0001 /*
0002  * Licensed to the Apache Software Foundation (ASF) under one or more
0003  * contributor license agreements.  See the NOTICE file distributed with
0004  * this work for additional information regarding copyright ownership.
0005  * The ASF licenses this file to You under the Apache License, Version 2.0
0006  * (the "License"); you may not use this file except in compliance with
0007  * the License.  You may obtain a copy of the License at
0008  *
0009  *      http://www.apache.org/licenses/LICENSE-2.0
0010  *
0011  * Unless required by applicable law or agreed to in writing, software
0012  * distributed under the License is distributed on an "AS IS" BASIS,
0013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014  * See the License for the specific language governing permissions and
0015  * limitations under the License.
0016  */
0017 
0018 /*
0019  * $Id$
0020  */
0021 
0022 #if !defined(XERCESC_INCLUDE_GUARD_HASH2KEYSSETOF_HPP)
0023 #define XERCESC_INCLUDE_GUARD_HASH2KEYSSETOF_HPP
0024 
0025 
0026 #include <xercesc/util/Hashers.hpp>
0027 #include <xercesc/util/IllegalArgumentException.hpp>
0028 #include <xercesc/util/NoSuchElementException.hpp>
0029 #include <xercesc/util/RuntimeException.hpp>
0030 #include <xercesc/util/PlatformUtils.hpp>
0031 
0032 XERCES_CPP_NAMESPACE_BEGIN
0033 
0034 // This hash table is similar to Hash2KeysSetOf with an additional integer as key2
0035 
0036 //  Forward declare the enumerator so it can be our friend.
0037 //
0038 template <class THasher>
0039 class Hash2KeysSetOfEnumerator;
0040 
0041 //
0042 //  This should really be a nested class, but some of the compilers we
0043 //  have to support cannot deal with that!
0044 //
0045 struct Hash2KeysSetBucketElem
0046 {
0047     Hash2KeysSetBucketElem*              fNext;
0048     const void*                          fKey1;
0049     int                                  fKey2;
0050 };
0051 
0052 
0053 template <class THasher>
0054 class Hash2KeysSetOf : public XMemory
0055 {
0056 public:
0057     // -----------------------------------------------------------------------
0058     //  Constructors and Destructor
0059     // -----------------------------------------------------------------------
0060 
0061     Hash2KeysSetOf(
0062       const XMLSize_t modulus,
0063       MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
0064 
0065     Hash2KeysSetOf(
0066       const XMLSize_t modulus,
0067       const THasher& hasher,
0068       MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
0069 
0070     ~Hash2KeysSetOf();
0071 
0072 
0073     // -----------------------------------------------------------------------
0074     //  Element management
0075     // -----------------------------------------------------------------------
0076     bool isEmpty() const;
0077     bool containsKey(const void* const key1, const int key2) const;
0078     void removeKey(const void* const key1, const int key2);
0079     void removeKey(const void* const key1);
0080     void removeAll();
0081 
0082     // -----------------------------------------------------------------------
0083     //  Getters
0084     // -----------------------------------------------------------------------
0085     MemoryManager* getMemoryManager() const;
0086     XMLSize_t      getHashModulus()   const;
0087 
0088     // -----------------------------------------------------------------------
0089     //  Putters
0090     // -----------------------------------------------------------------------
0091     void put(const void* key1, int key2);
0092     bool putIfNotPresent(const void* key1, int key2);
0093 
0094 private :
0095     // -----------------------------------------------------------------------
0096     //  Declare our friends
0097     // -----------------------------------------------------------------------
0098     friend class Hash2KeysSetOfEnumerator<THasher>;
0099 
0100 
0101 private:
0102     // -----------------------------------------------------------------------
0103     //  Unimplemented constructors and operators
0104     // -----------------------------------------------------------------------
0105     Hash2KeysSetOf(const Hash2KeysSetOf<THasher>&);
0106     Hash2KeysSetOf<THasher>& operator=(const Hash2KeysSetOf<THasher>&);
0107 
0108     // -----------------------------------------------------------------------
0109     //  Private methods
0110     // -----------------------------------------------------------------------
0111     Hash2KeysSetBucketElem* findBucketElem(const void* const key1, const int key2, XMLSize_t& hashVal);
0112     const Hash2KeysSetBucketElem* findBucketElem(const void* const key1, const int key2, XMLSize_t& hashVal) const;
0113     void initialize(const XMLSize_t modulus);
0114     void rehash();
0115 
0116 
0117     // -----------------------------------------------------------------------
0118     //  Data members
0119     //
0120     //  fBucketList
0121     //      This is the array that contains the heads of all of the list
0122     //      buckets, one for each possible hash value.
0123     //
0124     //  fHashModulus
0125     //      The modulus used for this hash table, to hash the keys. This is
0126     //      also the number of elements in the bucket list.
0127     //
0128     //  fCount
0129     //      The number of elements currently in the map
0130     //
0131     //  fHash
0132     //      The hasher for the key1 data type.
0133     // -----------------------------------------------------------------------
0134     MemoryManager*                      fMemoryManager;
0135     Hash2KeysSetBucketElem**            fBucketList;
0136     XMLSize_t                           fHashModulus;
0137     XMLSize_t                           fCount;
0138     Hash2KeysSetBucketElem*             fAvailable;
0139     THasher                             fHasher;
0140 };
0141 
0142 
0143 
0144 //
0145 //  An enumerator for a value array. It derives from the basic enumerator
0146 //  class, so that value vectors can be generically enumerated.
0147 //
0148 template <class THasher>
0149 class Hash2KeysSetOfEnumerator : public XMemory
0150 {
0151 public :
0152     // -----------------------------------------------------------------------
0153     //  Constructors and Destructor
0154     // -----------------------------------------------------------------------
0155     Hash2KeysSetOfEnumerator(Hash2KeysSetOf<THasher>* const toEnum
0156                            , const bool adopt = false
0157                            , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
0158     virtual ~Hash2KeysSetOfEnumerator();
0159 
0160 
0161     // -----------------------------------------------------------------------
0162     //  Enum interface
0163     // -----------------------------------------------------------------------
0164     bool hasMoreElements() const;
0165     void Reset();
0166 
0167     // -----------------------------------------------------------------------
0168     //  New interface
0169     // -----------------------------------------------------------------------
0170     void nextElementKey(const void*&, int&);
0171     void setPrimaryKey(const void* key);
0172 
0173 private :
0174     // -----------------------------------------------------------------------
0175     //  Unimplemented constructors and operators
0176     // -----------------------------------------------------------------------
0177     Hash2KeysSetOfEnumerator(const Hash2KeysSetOfEnumerator<THasher>&);
0178     Hash2KeysSetOfEnumerator<THasher>& operator=(const Hash2KeysSetOfEnumerator<THasher>&);
0179 
0180     // -----------------------------------------------------------------------
0181     //  Private methods
0182     // -----------------------------------------------------------------------
0183     void findNext();
0184 
0185 
0186     // -----------------------------------------------------------------------
0187     //  Data Members
0188     //
0189     //  fAdopted
0190     //      Indicates whether we have adopted the passed vector. If so then
0191     //      we delete the vector when we are destroyed.
0192     //
0193     //  fCurElem
0194     //      This is the current bucket bucket element that we are on.
0195     //
0196     //  fCurHash
0197     //      The is the current hash buck that we are working on. Once we hit
0198     //      the end of the bucket that fCurElem is in, then we have to start
0199     //      working this one up to the next non-empty bucket.
0200     //
0201     //  fToEnum
0202     //      The value array being enumerated.
0203     //
0204     //  fLockPrimaryKey
0205     //      Indicates that we are requested to iterate over the secondary keys
0206     //      associated with the given primary key
0207     //
0208     // -----------------------------------------------------------------------
0209     bool                                    fAdopted;
0210     Hash2KeysSetBucketElem*                 fCurElem;
0211     XMLSize_t                               fCurHash;
0212     Hash2KeysSetOf<THasher>*                fToEnum;
0213     MemoryManager* const                    fMemoryManager;
0214     const void*                             fLockPrimaryKey;
0215 };
0216 
0217 XERCES_CPP_NAMESPACE_END
0218 
0219 #if !defined(XERCES_TMPLSINC)
0220 #include <xercesc/util/Hash2KeysSetOf.c>
0221 #endif
0222 
0223 #endif