Xalan-C++ API Reference 1.12.0
XalanDOMStringHashTable.hpp
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18#if !defined(XALANDOMSTRINGHASHTABLE_HEADER_GUARD_1357924680)
19#define XALANDOMSTRINGHASHTABLE_HEADER_GUARD_1357924680
20
21
22
23// Base include file. Must be first.
25
26
27
29
30
31
33
34
35
36namespace XALAN_CPP_NAMESPACE {
37
38
39
41{
42public:
43
49
50 enum { eDefaultBucketCount = 101, eDefaultBucketSize = 15 };
51
52
53 /**
54 * Create a hash table.
55 *
56 * @param theBucketCount The number of buckets to use for the hash table. This should be a prime number for best results.
57 * @param theBucketSize The initial size of each bucket in the hash table.
58 */
59 explicit
61 MemoryManager& theManager,
62 size_t theBucketCount = eDefaultBucketCount,
63 bucket_size_type theBucketSize = eDefaultBucketSize);
64
66
67 /**
68 * Clear the hash table.
69 */
70 void
72
73 /**
74 * Get the number of strings in the table
75 *
76 * @return The number of strings in the table
77 */
78 size_t
79 size() const
80 {
81 return m_count;
82 }
83
84 /**
85 * Get the number of buckets in the table
86 *
87 * @return The number of buckets in the table
88 */
89 size_t
91 {
92 return m_bucketCount;
93 }
94
95 /**
96 * Get the size of each of the buckets in the table
97 *
98 * @param A vector to return the bucket counts.
99 */
100 void
102
103 /**
104 * Get the collision count. Release builds will always
105 * return 0.
106 *
107 * @return The number of collisions. Valid only for non-release builds.
108 */
109 size_t
111 {
112 return m_collisions;
113 }
114
115 /**
116 * Find a string. If the string is not found, return null.
117 *
118 * @param theString The string to find.
119 * @param theBucketIndex The index of the bucket for the string.
120 * @return a pointer to the string, or null if not found.
121 */
122 const XalanDOMString*
125 size_t* theBucketIndex = 0) const;
126
127 /**
128 * Find a string. If the string is not found, return null.
129 * If theBucketIndex is not null, the variable pointed to
130 * will be updated with the bucket index that was calculated
131 * for the string. This index can be used in a later call to
132 * insert() to avoid recalculating the index.
133 *
134 * @param theString The string to find.
135 * @param theLength The number of characters in the string.
136 * @param theBucketIndex A pointer to a parameter to get the bucket index
137 * @return a pointer to the string, or null if not found.
138 */
139 const XalanDOMString*
141 const XalanDOMChar* theString,
142 XalanDOMString::size_type theLength = XalanDOMString::npos,
143 size_t* theBucketIndex = 0) const;
144
145 /**
146 * Insert a pointer to a string into the table. If the string
147 * is already present, the string will still be added, but it
148 * will never be found, since it will be placed after the identical
149 * string.
150 *
151 * Note that this class only stores a _pointer_ to a XalanDOMString.
152 * It's expected that the string will be allocated and managed outside
153 * of the hash table.
154 *
155 * @param theString The string to insert.
156 */
157 void
159
160 /**
161 * Insert a pointer to a string into the table. If the string
162 * is already present, the string will still be added, but it
163 * will never be found, since it will be placed after the identical
164 * string. theBucketIndex _must_ be the index returned from a
165 * previous call to find. If not, then the behavior is undefined.
166 * This is meant as an optimization to avoid re-hashing the string.
167 *
168 * Note that this class only stores a _pointer_ to a XalanDOMString.
169 * It's expected that the string will be allocated and managed outside
170 * of the hash table.
171 *
172 * @param theString The string to insert.
173 * @param theBucketIndex The index of the bucket for the string.
174 */
175 void
178 size_t theBucketIndex);
179
180 MemoryManager&
182 {
183 return m_buckets.getMemoryManager();
184 }
185
186 const MemoryManager&
188 {
189 return m_buckets.getMemoryManager();
190 }
191
192private:
193
194 // Not implemented, for now...
196
198 operator=(const XalanDOMStringHashTable&);
199
200 bool
202
203
204 // Data members...
205 const size_t m_bucketCount;
206
207 const bucket_size_type m_bucketSize;
208
209 BucketVectorType m_buckets;
210
211 size_t m_count;
212
213 size_t m_collisions;
214};
215
216
217
218}
219
220
221
222#endif // !defined(XALANDOMSTRINGPOOL_HEADER_GUARD_1357924680)
#define XALAN_PLATFORMSUPPORT_EXPORT
#define XALAN_CPP_NAMESPACE
Xalan-C++ namespace, including major and minor version.
size_t bucketCount() const
Get the number of buckets in the table.
void clear()
Clear the hash table.
size_t size() const
Get the number of strings in the table.
const XalanDOMString * find(const XalanDOMChar *theString, XalanDOMString::size_type theLength=XalanDOMString::npos, size_t *theBucketIndex=0) const
Find a string.
void insert(const XalanDOMString &theString, size_t theBucketIndex)
Insert a pointer to a string into the table.
ExplicitMemoryManagedConstructionTraits< BucketType > ConstructionTraits
void getBucketCounts(BucketCountsType &theVector) const
Get the size of each of the buckets in the table.
size_t collisions() const
Get the collision count.
const XalanDOMString * find(const XalanDOMString &theString, size_t *theBucketIndex=0) const
Find a string.
XalanVector< BucketType, ConstructionTraits > BucketVectorType
void insert(const XalanDOMString &theString)
Insert a pointer to a string into the table.
XalanVector< bucket_size_type > BucketCountsType
const MemoryManager & getMemoryManager() const
XalanVector< const XalanDOMString * > BucketType
XalanDOMStringHashTable(MemoryManager &theManager, size_t theBucketCount=eDefaultBucketCount, bucket_size_type theBucketSize=eDefaultBucketSize)
Create a hash table.
bool operator==(const XalanVector< Type > &theLHS, const XalanVector< Type > &theRHS)