|
||||
File indexing completed on 2025-01-18 10:15:14
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_VALUEHASHTABLEOF_HPP) 0023 #define XERCESC_INCLUDE_GUARD_VALUEHASHTABLEOF_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 // Forward declare the enumerator so it can be our friend. 0035 // 0036 template <class TVal, class THasher = StringHasher> 0037 class ValueHashTableOfEnumerator; 0038 0039 0040 // 0041 // This should really be a nested class, but some of the compilers we 0042 // have to support cannot deal with that! 0043 // 0044 template <class TVal> 0045 struct ValueHashTableBucketElem 0046 { 0047 ValueHashTableBucketElem(void* key, const TVal& value, ValueHashTableBucketElem<TVal>* next) 0048 : fData(value), fNext(next), fKey(key) 0049 { 0050 } 0051 ValueHashTableBucketElem(){}; 0052 ~ValueHashTableBucketElem(){}; 0053 0054 TVal fData; 0055 ValueHashTableBucketElem<TVal>* fNext; 0056 void* fKey; 0057 0058 private: 0059 // ----------------------------------------------------------------------- 0060 // Unimplemented constructors and operators 0061 // ----------------------------------------------------------------------- 0062 ValueHashTableBucketElem(const ValueHashTableBucketElem<TVal>&); 0063 ValueHashTableBucketElem<TVal>& operator=(const ValueHashTableBucketElem<TVal>&); 0064 }; 0065 0066 0067 template <class TVal, class THasher = StringHasher> 0068 class ValueHashTableOf : public XMemory 0069 { 0070 public: 0071 // ----------------------------------------------------------------------- 0072 // Constructors and Destructor 0073 // ----------------------------------------------------------------------- 0074 ValueHashTableOf( 0075 const XMLSize_t modulus, 0076 MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); 0077 0078 ValueHashTableOf( 0079 const XMLSize_t modulus, 0080 const THasher& hasher, 0081 MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); 0082 0083 ~ValueHashTableOf(); 0084 0085 0086 // ----------------------------------------------------------------------- 0087 // Element management 0088 // ----------------------------------------------------------------------- 0089 bool isEmpty() const; 0090 bool containsKey(const void* const key) const; 0091 void removeKey(const void* const key); 0092 void removeAll(); 0093 0094 0095 // ----------------------------------------------------------------------- 0096 // Getters 0097 // ----------------------------------------------------------------------- 0098 TVal& get(const void* const key, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); 0099 const TVal& get(const void* const key) const; 0100 0101 0102 // ----------------------------------------------------------------------- 0103 // Putters 0104 // ----------------------------------------------------------------------- 0105 void put(void* key, const TVal& valueToAdopt); 0106 0107 0108 private : 0109 // ----------------------------------------------------------------------- 0110 // Declare our friends 0111 // ----------------------------------------------------------------------- 0112 friend class ValueHashTableOfEnumerator<TVal, THasher>; 0113 0114 private: 0115 // ----------------------------------------------------------------------- 0116 // Unimplemented constructors and operators 0117 // ----------------------------------------------------------------------- 0118 ValueHashTableOf(const ValueHashTableOf<TVal, THasher>&); 0119 ValueHashTableOf<TVal, THasher>& operator=(const ValueHashTableOf<TVal, THasher>&); 0120 0121 // ----------------------------------------------------------------------- 0122 // Private methods 0123 // ----------------------------------------------------------------------- 0124 ValueHashTableBucketElem<TVal>* findBucketElem(const void* const key, XMLSize_t& hashVal); 0125 const ValueHashTableBucketElem<TVal>* findBucketElem(const void* const key, XMLSize_t& hashVal) const; 0126 void removeBucketElem(const void* const key, XMLSize_t& hashVal); 0127 void initialize(const XMLSize_t modulus); 0128 void rehash(); 0129 0130 0131 // ----------------------------------------------------------------------- 0132 // Data members 0133 // 0134 // fBucketList 0135 // This is the array that contains the heads of all of the list 0136 // buckets, one for each possible hash value. 0137 // 0138 // fHashModulus 0139 // The modulus used for this hash table, to hash the keys. This is 0140 // also the number of elements in the bucket list. 0141 // 0142 // fHash 0143 // The hasher for the key data type. 0144 // ----------------------------------------------------------------------- 0145 MemoryManager* fMemoryManager; 0146 ValueHashTableBucketElem<TVal>** fBucketList; 0147 XMLSize_t fHashModulus; 0148 XMLSize_t fInitialModulus; 0149 XMLSize_t fCount; 0150 THasher fHasher; 0151 }; 0152 0153 0154 0155 // 0156 // An enumerator for a value array. It derives from the basic enumerator 0157 // class, so that value vectors can be generically enumerated. 0158 // 0159 template <class TVal, class THasher> 0160 class ValueHashTableOfEnumerator : public XMLEnumerator<TVal>, public XMemory 0161 { 0162 public : 0163 // ----------------------------------------------------------------------- 0164 // Constructors and Destructor 0165 // ----------------------------------------------------------------------- 0166 ValueHashTableOfEnumerator(ValueHashTableOf<TVal, THasher>* const toEnum 0167 , const bool adopt = false 0168 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); 0169 virtual ~ValueHashTableOfEnumerator(); 0170 0171 0172 // ----------------------------------------------------------------------- 0173 // Enum interface 0174 // ----------------------------------------------------------------------- 0175 bool hasMoreElements() const; 0176 TVal& nextElement(); 0177 void Reset(); 0178 0179 // ----------------------------------------------------------------------- 0180 // New interface specific for key used in ValueHashable 0181 // ----------------------------------------------------------------------- 0182 void* nextElementKey(); 0183 0184 0185 private : 0186 // ----------------------------------------------------------------------- 0187 // Unimplemented constructors and operators 0188 // ----------------------------------------------------------------------- 0189 ValueHashTableOfEnumerator(const ValueHashTableOfEnumerator<TVal, THasher>&); 0190 ValueHashTableOfEnumerator<TVal, THasher>& operator=(const ValueHashTableOfEnumerator<TVal, THasher>&); 0191 0192 // ----------------------------------------------------------------------- 0193 // Private methods 0194 // ----------------------------------------------------------------------- 0195 void findNext(); 0196 0197 0198 // ----------------------------------------------------------------------- 0199 // Data Members 0200 // 0201 // fAdopted 0202 // Indicates whether we have adopted the passed vector. If so then 0203 // we delete the vector when we are destroyed. 0204 // 0205 // fCurElem 0206 // This is the current bucket bucket element that we are on. 0207 // 0208 // fCurHash 0209 // The is the current hash buck that we are working on. Once we hit 0210 // the end of the bucket that fCurElem is in, then we have to start 0211 // working this one up to the next non-empty bucket. 0212 // 0213 // fToEnum 0214 // The value array being enumerated. 0215 // ----------------------------------------------------------------------- 0216 bool fAdopted; 0217 ValueHashTableBucketElem<TVal>* fCurElem; 0218 XMLSize_t fCurHash; 0219 ValueHashTableOf<TVal, THasher>* fToEnum; 0220 MemoryManager* const fMemoryManager; 0221 }; 0222 0223 XERCES_CPP_NAMESPACE_END 0224 0225 #if !defined(XERCES_TMPLSINC) 0226 #include <xercesc/util/ValueHashTableOf.c> 0227 #endif 0228 0229 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |