Coverage Report

Created: 2026-05-24 07:16

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/xerces-c/src/xercesc/util/ValueHashTableOf.hpp
Line
Count
Source
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 *
9
 *      http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
18
/*
19
 * $Id: ValueHashTableOf.hpp 679340 2008-07-24 10:28:29Z borisk $
20
 */
21
22
#if !defined(XERCESC_INCLUDE_GUARD_VALUEHASHTABLEOF_HPP)
23
#define XERCESC_INCLUDE_GUARD_VALUEHASHTABLEOF_HPP
24
25
26
#include <xercesc/util/Hashers.hpp>
27
#include <xercesc/util/IllegalArgumentException.hpp>
28
#include <xercesc/util/NoSuchElementException.hpp>
29
#include <xercesc/util/RuntimeException.hpp>
30
#include <xercesc/util/PlatformUtils.hpp>
31
32
XERCES_CPP_NAMESPACE_BEGIN
33
34
//  Forward declare the enumerator so it can be our friend.
35
//
36
template <class TVal, class THasher = StringHasher>
37
class ValueHashTableOfEnumerator;
38
39
40
//
41
//  This should really be a nested class, but some of the compilers we
42
//  have to support cannot deal with that!
43
//
44
template <class TVal>
45
struct ValueHashTableBucketElem
46
{
47
    ValueHashTableBucketElem(void* key, const TVal& value, ValueHashTableBucketElem<TVal>* next)
48
1.76k
    : fData(value), fNext(next), fKey(key)
49
1.76k
        {
50
1.76k
        }
xercesc_3_2::ValueHashTableBucketElem<xercesc_3_2::XSValue::DataType>::ValueHashTableBucketElem(void*, xercesc_3_2::XSValue::DataType const&, xercesc_3_2::ValueHashTableBucketElem<xercesc_3_2::XSValue::DataType>*)
Line
Count
Source
48
88
    : fData(value), fNext(next), fKey(key)
49
88
        {
50
88
        }
Unexecuted instantiation: xercesc_3_2::ValueHashTableBucketElem<unsigned int>::ValueHashTableBucketElem(void*, unsigned int const&, xercesc_3_2::ValueHashTableBucketElem<unsigned int>*)
xercesc_3_2::ValueHashTableBucketElem<bool>::ValueHashTableBucketElem(void*, bool const&, xercesc_3_2::ValueHashTableBucketElem<bool>*)
Line
Count
Source
48
1.58k
    : fData(value), fNext(next), fKey(key)
49
1.58k
        {
50
1.58k
        }
Unexecuted instantiation: xercesc_3_2::ValueHashTableBucketElem<xercesc_3_2::DOMLSParserFilter::FilterAction>::ValueHashTableBucketElem(void*, xercesc_3_2::DOMLSParserFilter::FilterAction const&, xercesc_3_2::ValueHashTableBucketElem<xercesc_3_2::DOMLSParserFilter::FilterAction>*)
xercesc_3_2::ValueHashTableBucketElem<unsigned short>::ValueHashTableBucketElem(void*, unsigned short const&, xercesc_3_2::ValueHashTableBucketElem<unsigned short>*)
Line
Count
Source
48
92
    : fData(value), fNext(next), fKey(key)
49
92
        {
50
92
        }
Unexecuted instantiation: xercesc_3_2::ValueHashTableBucketElem<char16_t>::ValueHashTableBucketElem(void*, char16_t const&, xercesc_3_2::ValueHashTableBucketElem<char16_t>*)
51
    ValueHashTableBucketElem(){};
52
    ~ValueHashTableBucketElem(){};
53
54
    TVal                            fData;
55
    ValueHashTableBucketElem<TVal>* fNext;
56
    void*                           fKey;
57
58
private:
59
    // -----------------------------------------------------------------------
60
    //  Unimplemented constructors and operators
61
    // -----------------------------------------------------------------------
62
    ValueHashTableBucketElem(const ValueHashTableBucketElem<TVal>&);
63
    ValueHashTableBucketElem<TVal>& operator=(const ValueHashTableBucketElem<TVal>&);
64
};
65
66
67
template <class TVal, class THasher = StringHasher>
68
class ValueHashTableOf : public XMemory
69
{
70
public:
71
    // -----------------------------------------------------------------------
72
    //  Constructors and Destructor
73
    // -----------------------------------------------------------------------
74
    ValueHashTableOf(
75
      const XMLSize_t modulus,
76
      MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
77
78
    ValueHashTableOf(
79
      const XMLSize_t modulus,
80
      const THasher& hasher,
81
      MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
82
83
    ~ValueHashTableOf();
84
85
86
    // -----------------------------------------------------------------------
87
    //  Element management
88
    // -----------------------------------------------------------------------
89
    bool isEmpty() const;
90
    bool containsKey(const void* const key) const;
91
    void removeKey(const void* const key);
92
    void removeAll();
93
94
95
    // -----------------------------------------------------------------------
96
    //  Getters
97
    // -----------------------------------------------------------------------
98
    TVal& get(const void* const key, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
99
    const TVal& get(const void* const key) const;
100
101
102
    // -----------------------------------------------------------------------
103
    //  Putters
104
    // -----------------------------------------------------------------------
105
    void put(void* key, const TVal& valueToAdopt);
106
107
108
private :
109
    // -----------------------------------------------------------------------
110
    //  Declare our friends
111
    // -----------------------------------------------------------------------
112
    friend class ValueHashTableOfEnumerator<TVal, THasher>;
113
114
private:
115
    // -----------------------------------------------------------------------
116
    //  Unimplemented constructors and operators
117
    // -----------------------------------------------------------------------
118
    ValueHashTableOf(const ValueHashTableOf<TVal, THasher>&);
119
    ValueHashTableOf<TVal, THasher>& operator=(const ValueHashTableOf<TVal, THasher>&);
120
121
    // -----------------------------------------------------------------------
122
    //  Private methods
123
    // -----------------------------------------------------------------------
124
    ValueHashTableBucketElem<TVal>* findBucketElem(const void* const key, XMLSize_t& hashVal);
125
    const ValueHashTableBucketElem<TVal>* findBucketElem(const void* const key, XMLSize_t& hashVal) const;
126
    void removeBucketElem(const void* const key, XMLSize_t& hashVal);
127
    void initialize(const XMLSize_t modulus);
128
    void rehash();
129
130
131
    // -----------------------------------------------------------------------
132
    //  Data members
133
    //
134
    //  fBucketList
135
    //      This is the array that contains the heads of all of the list
136
    //      buckets, one for each possible hash value.
137
    //
138
    //  fHashModulus
139
    //      The modulus used for this hash table, to hash the keys. This is
140
    //      also the number of elements in the bucket list.
141
    //
142
    //  fHash
143
    //      The hasher for the key data type.
144
    // -----------------------------------------------------------------------
145
    MemoryManager*                   fMemoryManager;
146
    ValueHashTableBucketElem<TVal>** fBucketList;
147
    XMLSize_t                        fHashModulus;
148
    XMLSize_t                        fInitialModulus;
149
    XMLSize_t                        fCount;
150
    THasher                          fHasher;
151
};
152
153
154
155
//
156
//  An enumerator for a value array. It derives from the basic enumerator
157
//  class, so that value vectors can be generically enumerated.
158
//
159
template <class TVal, class THasher>
160
class ValueHashTableOfEnumerator : public XMLEnumerator<TVal>, public XMemory
161
{
162
public :
163
    // -----------------------------------------------------------------------
164
    //  Constructors and Destructor
165
    // -----------------------------------------------------------------------
166
    ValueHashTableOfEnumerator(ValueHashTableOf<TVal, THasher>* const toEnum
167
                               , const bool adopt = false
168
                               , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
169
    virtual ~ValueHashTableOfEnumerator();
170
171
172
    // -----------------------------------------------------------------------
173
    //  Enum interface
174
    // -----------------------------------------------------------------------
175
    bool hasMoreElements() const;
176
    TVal& nextElement();
177
    void Reset();
178
179
    // -----------------------------------------------------------------------
180
    //  New interface specific for key used in ValueHashable
181
    // -----------------------------------------------------------------------
182
    void* nextElementKey();
183
184
185
private :
186
    // -----------------------------------------------------------------------
187
    //  Unimplemented constructors and operators
188
    // -----------------------------------------------------------------------
189
    ValueHashTableOfEnumerator(const ValueHashTableOfEnumerator<TVal, THasher>&);
190
    ValueHashTableOfEnumerator<TVal, THasher>& operator=(const ValueHashTableOfEnumerator<TVal, THasher>&);
191
192
    // -----------------------------------------------------------------------
193
    //  Private methods
194
    // -----------------------------------------------------------------------
195
    void findNext();
196
197
198
    // -----------------------------------------------------------------------
199
    //  Data Members
200
    //
201
    //  fAdopted
202
    //      Indicates whether we have adopted the passed vector. If so then
203
    //      we delete the vector when we are destroyed.
204
    //
205
    //  fCurElem
206
    //      This is the current bucket bucket element that we are on.
207
    //
208
    //  fCurHash
209
    //      The is the current hash buck that we are working on. Once we hit
210
    //      the end of the bucket that fCurElem is in, then we have to start
211
    //      working this one up to the next non-empty bucket.
212
    //
213
    //  fToEnum
214
    //      The value array being enumerated.
215
    // -----------------------------------------------------------------------
216
    bool                             fAdopted;
217
    ValueHashTableBucketElem<TVal>*  fCurElem;
218
    XMLSize_t                        fCurHash;
219
    ValueHashTableOf<TVal, THasher>* fToEnum;
220
    MemoryManager* const             fMemoryManager;
221
};
222
223
XERCES_CPP_NAMESPACE_END
224
225
#if !defined(XERCES_TMPLSINC)
226
#include <xercesc/util/ValueHashTableOf.c>
227
#endif
228
229
#endif