00001 /* 00002 * Licensed to the Apache Software Foundation (ASF) under one 00003 * or more contributor license agreements. See the NOTICE file 00004 * distributed with this work for additional information 00005 * regarding copyright ownership. The ASF licenses this file 00006 * to you under the Apache License, Version 2.0 (the "License"); 00007 * you may not use this file except in compliance with the License. 00008 * You may obtain a copy of the License at 00009 * 00010 * http://www.apache.org/licenses/LICENSE-2.0 00011 * 00012 * Unless required by applicable law or agreed to in writing, software 00013 * distributed under the License is distributed on an "AS IS" BASIS, 00014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 * See the License for the specific language governing permissions and 00016 * limitations under the License. 00017 */ 00018 #if !defined(XALANDOMSTRINGHASHTABLE_HEADER_GUARD_1357924680) 00019 #define XALANDOMSTRINGHASHTABLE_HEADER_GUARD_1357924680 00020 00021 00022 00023 // Base include file. Must be first. 00024 #include <xalanc/PlatformSupport/PlatformSupportDefinitions.hpp> 00025 00026 00027 00028 #include <xalanc/Include/XalanVector.hpp> 00029 00030 00031 00032 #include <xalanc/XalanDOM/XalanDOMString.hpp> 00033 00034 00035 00036 XALAN_CPP_NAMESPACE_BEGIN 00037 00038 00039 00040 class XALAN_PLATFORMSUPPORT_EXPORT XalanDOMStringHashTable 00041 { 00042 public: 00043 00044 typedef XalanVector<const XalanDOMString*> BucketType; 00045 typedef BucketType::size_type bucket_size_type; 00046 typedef XalanVector<bucket_size_type> BucketCountsType; 00047 typedef ExplicitMemoryManagedConstructionTraits<BucketType> ConstructionTraits; 00048 typedef XalanVector<BucketType, ConstructionTraits> BucketVectorType; 00049 00050 enum { eDefaultBucketCount = 101, eDefaultBucketSize = 15 }; 00051 00052 00053 /** 00054 * Create a hash table. 00055 * 00056 * @param theBucketCount The number of buckets to use for the hash table. This should be a prime number for best results. 00057 * @param theBucketSize The initial size of each bucket in the hash table. 00058 */ 00059 explicit 00060 XalanDOMStringHashTable( 00061 MemoryManager& theManager, 00062 size_t theBucketCount = eDefaultBucketCount, 00063 bucket_size_type theBucketSize = eDefaultBucketSize); 00064 00065 ~XalanDOMStringHashTable() { } 00066 00067 /** 00068 * Clear the hash table. 00069 */ 00070 void 00071 clear(); 00072 00073 /** 00074 * Get the number of strings in the table 00075 * 00076 * @return The number of strings in the table 00077 */ 00078 size_t 00079 size() const 00080 { 00081 return m_count; 00082 } 00083 00084 /** 00085 * Get the number of buckets in the table 00086 * 00087 * @return The number of buckets in the table 00088 */ 00089 size_t 00090 bucketCount() const 00091 { 00092 return m_bucketCount; 00093 } 00094 00095 /** 00096 * Get the size of each of the buckets in the table 00097 * 00098 * @param A vector to return the bucket counts. 00099 */ 00100 void 00101 getBucketCounts(BucketCountsType& theVector) const; 00102 00103 /** 00104 * Get the collision count. Release builds will always 00105 * return 0. 00106 * 00107 * @return The number of collisions. Valid only for non-release builds. 00108 */ 00109 size_t 00110 collisions() const 00111 { 00112 return m_collisions; 00113 } 00114 00115 /** 00116 * Find a string. If the string is not found, return null. 00117 * 00118 * @param theString The string to find. 00119 * @param theBucketIndex The index of the bucket for the string. 00120 * @return a pointer to the string, or null if not found. 00121 */ 00122 const XalanDOMString* 00123 find( 00124 const XalanDOMString& theString, 00125 size_t* theBucketIndex = 0) const; 00126 00127 /** 00128 * Find a string. If the string is not found, return null. 00129 * If theBucketIndex is not null, the variable pointed to 00130 * will be updated with the bucket index that was calculated 00131 * for the string. This index can be used in a later call to 00132 * insert() to avoid recalculating the index. 00133 * 00134 * @param theString The string to find. 00135 * @param theLength The number of characters in the string. 00136 * @param theBucketIndex A pointer to a parameter to get the bucket index 00137 * @return a pointer to the string, or null if not found. 00138 */ 00139 const XalanDOMString* 00140 find( 00141 const XalanDOMChar* theString, 00142 XalanDOMString::size_type theLength = XalanDOMString::npos, 00143 size_t* theBucketIndex = 0) const; 00144 00145 /** 00146 * Insert a pointer to a string into the table. If the string 00147 * is already present, the string will still be added, but it 00148 * will never be found, since it will be placed after the identical 00149 * string. 00150 * 00151 * Note that this class only stores a _pointer_ to a XalanDOMString. 00152 * It's expected that the string will be allocated and managed outside 00153 * of the hash table. 00154 * 00155 * @param theString The string to insert. 00156 */ 00157 void 00158 insert(const XalanDOMString& theString); 00159 00160 /** 00161 * Insert a pointer to a string into the table. If the string 00162 * is already present, the string will still be added, but it 00163 * will never be found, since it will be placed after the identical 00164 * string. theBucketIndex _must_ be the index returned from a 00165 * previous call to find. If not, then the behavior is undefined. 00166 * This is meant as an optimization to avoid re-hashing the string. 00167 * 00168 * Note that this class only stores a _pointer_ to a XalanDOMString. 00169 * It's expected that the string will be allocated and managed outside 00170 * of the hash table. 00171 * 00172 * @param theString The string to insert. 00173 * @param theBucketIndex The index of the bucket for the string. 00174 */ 00175 void 00176 insert( 00177 const XalanDOMString& theString, 00178 size_t theBucketIndex); 00179 00180 MemoryManager& 00181 getMemoryManager() 00182 { 00183 return m_buckets.getMemoryManager(); 00184 } 00185 00186 const MemoryManager& 00187 getMemoryManager() const 00188 { 00189 return m_buckets.getMemoryManager(); 00190 } 00191 00192 private: 00193 00194 // Not implemented, for now... 00195 XalanDOMStringHashTable(const XalanDOMStringHashTable&); 00196 00197 XalanDOMStringHashTable& 00198 operator=(const XalanDOMStringHashTable&); 00199 00200 bool 00201 operator==(const XalanDOMStringHashTable&) const; 00202 00203 00204 // Data members... 00205 const size_t m_bucketCount; 00206 00207 const bucket_size_type m_bucketSize; 00208 00209 BucketVectorType m_buckets; 00210 00211 size_t m_count; 00212 00213 size_t m_collisions; 00214 }; 00215 00216 00217 00218 XALAN_CPP_NAMESPACE_END 00219 00220 00221 00222 #endif // !defined(XALANDOMSTRINGPOOL_HEADER_GUARD_1357924680)
Doxygen and GraphViz are used to generate this API documentation from the Xalan-C header files.
Xalan-C++ XSLT Processor Version 1.11 |
|