source: icXML/icXML-devel/src/xercesc/util/Hash2KeysSetOf.hpp @ 2722

Last change on this file since 2722 was 2722, checked in by cameron, 6 years ago

Original Xerces files with import mods for icxercesc

File size: 8.2 KB
Line 
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: Hash2KeysSetOf.hpp 883368 2009-11-23 15:28:19Z amassari $
20 */
21
22#if !defined(XERCESC_INCLUDE_GUARD_HASH2KEYSSETOF_HPP)
23#define XERCESC_INCLUDE_GUARD_HASH2KEYSSETOF_HPP
24
25
26#include <icxercesc/util/Hashers.hpp>
27#include <xercesc/util/IllegalArgumentException.hpp>
28#include <xercesc/util/NoSuchElementException.hpp>
29#include <xercesc/util/RuntimeException.hpp>
30#include <icxercesc/util/PlatformUtils.hpp>
31
32XERCES_CPP_NAMESPACE_BEGIN
33
34// This hash table is similar to Hash2KeysSetOf with an additional integer as key2
35
36//  Forward declare the enumerator so it can be our friend.
37//
38template <class THasher>
39class Hash2KeysSetOfEnumerator;
40
41//
42//  This should really be a nested class, but some of the compilers we
43//  have to support cannot deal with that!
44//
45struct Hash2KeysSetBucketElem
46{
47    Hash2KeysSetBucketElem*              fNext;
48    const void*                          fKey1;
49    int                                  fKey2;
50};
51
52
53template <class THasher>
54class Hash2KeysSetOf : public XMemory
55{
56public:
57    // -----------------------------------------------------------------------
58    //  Constructors and Destructor
59    // -----------------------------------------------------------------------
60
61    Hash2KeysSetOf(
62      const XMLSize_t modulus,
63      MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
64
65    Hash2KeysSetOf(
66      const XMLSize_t modulus,
67      const THasher& hasher,
68      MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
69
70    ~Hash2KeysSetOf();
71
72
73    // -----------------------------------------------------------------------
74    //  Element management
75    // -----------------------------------------------------------------------
76    bool isEmpty() const;
77    bool containsKey(const void* const key1, const int key2) const;
78    void removeKey(const void* const key1, const int key2);
79    void removeKey(const void* const key1);
80    void removeAll();
81
82    // -----------------------------------------------------------------------
83    //  Getters
84    // -----------------------------------------------------------------------
85    MemoryManager* getMemoryManager() const;
86    XMLSize_t      getHashModulus()   const;
87
88    // -----------------------------------------------------------------------
89    //  Putters
90    // -----------------------------------------------------------------------
91        void put(const void* key1, int key2);
92        bool putIfNotPresent(const void* key1, int key2);
93
94private :
95    // -----------------------------------------------------------------------
96    //  Declare our friends
97    // -----------------------------------------------------------------------
98    friend class Hash2KeysSetOfEnumerator<THasher>;
99
100
101private:
102    // -----------------------------------------------------------------------
103    //  Unimplemented constructors and operators
104    // -----------------------------------------------------------------------
105    Hash2KeysSetOf(const Hash2KeysSetOf<THasher>&);
106    Hash2KeysSetOf<THasher>& operator=(const Hash2KeysSetOf<THasher>&);
107
108    // -----------------------------------------------------------------------
109    //  Private methods
110    // -----------------------------------------------------------------------
111    Hash2KeysSetBucketElem* findBucketElem(const void* const key1, const int key2, XMLSize_t& hashVal);
112    const Hash2KeysSetBucketElem* findBucketElem(const void* const key1, const int key2, XMLSize_t& hashVal) const;
113    void initialize(const XMLSize_t modulus);
114    void rehash();
115
116
117    // -----------------------------------------------------------------------
118    //  Data members
119    //
120    //  fBucketList
121    //      This is the array that contains the heads of all of the list
122    //      buckets, one for each possible hash value.
123    //
124    //  fHashModulus
125    //      The modulus used for this hash table, to hash the keys. This is
126    //      also the number of elements in the bucket list.
127    //
128    //  fCount
129    //      The number of elements currently in the map
130    //
131    //  fHash
132    //      The hasher for the key1 data type.
133    // -----------------------------------------------------------------------
134    MemoryManager*                      fMemoryManager;
135    Hash2KeysSetBucketElem**            fBucketList;
136    XMLSize_t                           fHashModulus;
137    XMLSize_t                           fCount;
138    Hash2KeysSetBucketElem*             fAvailable;
139    THasher                                             fHasher;
140};
141
142
143
144//
145//  An enumerator for a value array. It derives from the basic enumerator
146//  class, so that value vectors can be generically enumerated.
147//
148template <class THasher>
149class Hash2KeysSetOfEnumerator : public XMemory
150{
151public :
152    // -----------------------------------------------------------------------
153    //  Constructors and Destructor
154    // -----------------------------------------------------------------------
155    Hash2KeysSetOfEnumerator(Hash2KeysSetOf<THasher>* const toEnum
156                           , const bool adopt = false
157                           , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
158    virtual ~Hash2KeysSetOfEnumerator();
159
160
161    // -----------------------------------------------------------------------
162    //  Enum interface
163    // -----------------------------------------------------------------------
164    bool hasMoreElements() const;
165    void Reset();
166
167    // -----------------------------------------------------------------------
168    //  New interface
169    // -----------------------------------------------------------------------
170    void nextElementKey(const void*&, int&);
171    void setPrimaryKey(const void* key);
172
173private :
174    // -----------------------------------------------------------------------
175    //  Unimplemented constructors and operators
176    // -----------------------------------------------------------------------
177    Hash2KeysSetOfEnumerator(const Hash2KeysSetOfEnumerator<THasher>&);
178    Hash2KeysSetOfEnumerator<THasher>& operator=(const Hash2KeysSetOfEnumerator<THasher>&);
179
180    // -----------------------------------------------------------------------
181    //  Private methods
182    // -----------------------------------------------------------------------
183    void findNext();
184
185
186    // -----------------------------------------------------------------------
187    //  Data Members
188    //
189    //  fAdopted
190    //      Indicates whether we have adopted the passed vector. If so then
191    //      we delete the vector when we are destroyed.
192    //
193    //  fCurElem
194    //      This is the current bucket bucket element that we are on.
195    //
196    //  fCurHash
197    //      The is the current hash buck that we are working on. Once we hit
198    //      the end of the bucket that fCurElem is in, then we have to start
199    //      working this one up to the next non-empty bucket.
200    //
201    //  fToEnum
202    //      The value array being enumerated.
203    //
204    //  fLockPrimaryKey
205    //      Indicates that we are requested to iterate over the secondary keys
206    //      associated with the given primary key
207    //
208    // -----------------------------------------------------------------------
209    bool                                    fAdopted;
210    Hash2KeysSetBucketElem*                 fCurElem;
211    XMLSize_t                               fCurHash;
212    Hash2KeysSetOf<THasher>*                fToEnum;
213    MemoryManager* const                    fMemoryManager;
214    const void*                             fLockPrimaryKey;
215};
216
217XERCES_CPP_NAMESPACE_END
218
219#if !defined(XERCES_TMPLSINC)
220#include <xercesc/util/Hash2KeysSetOf.c>
221#endif
222
223#endif
Note: See TracBrowser for help on using the repository browser.