DCL 4.0
Loading...
Searching...
No Matches
__HASHMAP.h
Go to the documentation of this file.
1#ifdef __DCL_INTERNAL__
2
3__DCL_BEGIN_NAMESPACE
4
5#ifdef __COMPILE_StringToStringMap__
6 #define THIS_NAME __szStringToStringMap_h__
7 #define THIS_VALUE __T("dcl/__HASHMAP.h/StringToStringMap")
8 #define HASHMAP_T StringToStringMap
9 #define HASHFUN_T HashFun<String>
10 #define KEY_T String
11 #define VALUE_T String
12 #define HAVE_CONSTRUCTOR_KEY 1
13 #define HAVE_CONSTRUCTOR_VALUE 1
14#elif defined(__COMPILE_StringToPointerMap__)
15 #define THIS_NAME __szStringToPointerMap_h__
16 #define THIS_VALUE __T("dcl/__HASHMAP.h/StringToPointerMap")
17 #define HASHMAP_T StringToPointerMap
18 #define HASHFUN_T HashFun<String>
19 #define KEY_T String
20 #define VALUE_T void*
21 #define HAVE_CONSTRUCTOR_KEY 1
22 #define HAVE_CONSTRUCTOR_VALUE 0
23#elif defined(__COMPILE_IntToPointerMap__)
24 #define THIS_NAME __szIntToPointerMap_h__
25 #define THIS_VALUE __T("dcl/__HASHMAP.h/IntToPointerMap")
26 #define HASHMAP_T IntToPointerMap
27 #define HASHFUN_T HashFun<int>
28 #define KEY_T int
29 #define VALUE_T void*
30 #define HAVE_CONSTRUCTOR_KEY 0
31 #define HAVE_CONSTRUCTOR_VALUE 0
32#endif
33
34#if __DCL_HAVE_THIS_FILE__
35 static const char_t THIS_NAME[] = THIS_VALUE;
36 #undef __THIS_FILE__
37 #define __THIS_FILE__ THIS_NAME
38#endif
39
55class DCLCAPI HASHMAP_T : public Object
56{
58public:
59 virtual String toString() const;
60
61public:
62 struct Assoc
63 {
64 KEY_T key;
65 VALUE_T value;
66
67 Assoc() {}
68 Assoc(const KEY_T& _key, const VALUE_T& _value)
69 {
70 this->key = _key;
71 this->value = (VALUE_T) _value;
72 }
73 };
74
75 struct HashNode : public Assoc
76 {
78 };
79
80 class ConstIterator;
82 {
83 public:
84 Iterator(HashNode* _pNode, HASHMAP_T* _pMap);
85 Iterator& operator=(const Iterator& _it);
88 bool operator==(const Iterator& _it) const;
89 bool operator!=(const Iterator& _it) const;
90 Assoc& operator*() const;
91 protected:
94 friend class ConstIterator;
95 };
96
98 {
99 public:
100 ConstIterator(const HashNode* _pNode, const HASHMAP_T* _pMap);
101 ConstIterator(const ConstIterator& _it);
102 ConstIterator(const Iterator& _it);
106 bool operator==(const ConstIterator& _it) const;
107 bool operator!=(const ConstIterator& _it) const;
108 const Assoc& operator*() const;
109 protected:
112 };
113
114public:
115 virtual ~HASHMAP_T();
116 HASHMAP_T(size_t _bucketSize = 21);
117 void initBuckets(size_t _bucketSize);
118
119 HASHMAP_T(const HASHMAP_T& _src);
120 const HASHMAP_T& operator=(const HASHMAP_T& _src);
121
122 ConstIterator begin() const;
123 ConstIterator end() const;
124 Iterator begin();
125 Iterator end();
126 size_t bucketSize() const;
127 size_t size() const;
128 size_t sizeOfBucket(size_t _index) const;
129 bool isEmpty() const;
130 Iterator find(const KEY_T& _key);
131 ConstIterator find(const KEY_T& _key) const;
132 bool lookup(const KEY_T& _key, VALUE_T& _rValue) const;
133 VALUE_T& operator[](const KEY_T& _key);
134 size_t erase(const KEY_T& _key);
135 void clear();
136
137protected:
138 size_t bucketIndex(const KEY_T& _key) const;
139 HashNode* createNode(const KEY_T& _key);
140 void destroyNode(HashNode* _pNode);
141
142protected:
143 HASHFUN_T __hashFun;
144 size_t __size; // count of all elements
145 PointerArray __buckets;
146
147 friend class Iterator;
148 friend class ConstIterator;
149};
150
152
153inline
154HASHMAP_T
155::Iterator::Iterator(
156 HashNode* _pNode,
157 HASHMAP_T* _pMap
158 )
159{
160 __pNode = _pNode;
161 __pMap = _pMap;
162}
163
164inline
166HASHMAP_T
167::Iterator::operator = (const Iterator& _it)
168{
169 __pNode = _it.__pNode;
170 __pMap = _it.__pMap;
171 return *this;
172}
173
174inline
175bool
176HASHMAP_T
177::Iterator::operator == (const Iterator& _it) const
178{
179 return __pNode == _it.__pNode;
180}
181
182inline
183bool
184HASHMAP_T
185::Iterator::operator != (const Iterator& _it) const
186{
187 return __pNode != _it.__pNode;
188}
189
190inline
193{
194 return *__pNode;
195}
196
198
199inline
200HASHMAP_T
201::ConstIterator::ConstIterator(
202 const HashNode* _pNode,
203 const HASHMAP_T* _pMap
204 )
205{
206 __pNode = _pNode;
207 __pMap = _pMap;
208}
209
210inline
211HASHMAP_T
212::ConstIterator::ConstIterator(const ConstIterator& _it)
213{
214 __pNode = _it.__pNode;
215 __pMap = _it.__pMap;
216}
217
218inline
219HASHMAP_T
220::ConstIterator::ConstIterator(const Iterator& _it)
221{
222 __pNode = _it.__pNode;
223 __pMap = _it.__pMap;
224}
225
226inline
228HASHMAP_T
229::ConstIterator::operator=(const ConstIterator& _it)
230{
231 __pNode = _it.__pNode;
232 __pMap = _it.__pMap;
233 return *this;
234}
235
236inline
237bool
238HASHMAP_T
239::ConstIterator::operator == (const ConstIterator& _it) const
240{
241 return __pNode == _it.__pNode;
242}
243
244inline
245bool
246HASHMAP_T
247::ConstIterator::operator != (const ConstIterator& _it) const
248{
249 return __pNode != _it.__pNode;
250}
251
252inline
253const HASHMAP_T::Assoc&
254HASHMAP_T
255::ConstIterator::operator*() const
256{
257 return *__pNode;
258}
259
261
262inline
265{
266 return Iterator(NULL, this);
267}
268
269inline
272{
273 return ConstIterator(NULL, this);
274}
275
276inline
277size_t
279{
280 return __buckets.size();
281}
282
283inline
284size_t
286{
287 return __size;
288}
289
290inline
291bool
293{
294 return __size == 0;
295}
296
297#if __DCL_HAVE_THIS_FILE__
298 #undef __THIS_FILE__
299 #define __THIS_FILE__ __T(__FILE__)
300#endif
301
302#undef THIS_NAME
303#undef THIS_VALUE
304#undef HASHMAP_T
305#undef HASHFUN_T
306#undef KEY_T
307#undef VALUE_T
308#undef HAVE_CONSTRUCTOR_KEY
309#undef HAVE_CONSTRUCTOR_VALUE
310
311__DCL_END_NAMESPACE
312
313#endif // __DCL_INTERNAL__
DCLCAPI bool operator!=(const STRING_T &_str1, const STRING_T &_str2)
Definition __STRING.h:424
DCLCAPI bool operator==(const STRING_T &_str1, const STRING_T &_str2)
Definition __STRING.h:397
#define NULL
Definition Config.h:340
#define DCLCAPI
Definition Config.h:100
wchar_t char_t
Definition Config.h:275
#define DECLARE_CLASSINFO(class_name)
Definition Object.h:210
void CharsetConvertException *__fields clear()
const HASHMAP_T * __pMap
Definition __HASHMAP.h:110
ConstIterator(const HashNode *_pNode, const HASHMAP_T *_pMap)
Definition __HASHMAP.h:201
ConstIterator & operator++()
Definition __HASHMAP.cpp:73
const Assoc & operator*() const
Definition __HASHMAP.h:255
ConstIterator & operator=(const ConstIterator &_it)
Definition __HASHMAP.h:229
const HashNode * __pNode
Definition __HASHMAP.h:111
Iterator(HashNode *_pNode, HASHMAP_T *_pMap)
Definition __HASHMAP.h:155
friend class ConstIterator
Definition __HASHMAP.h:94
Assoc & operator*() const
Definition __HASHMAP.h:192
HASHMAP_T * __pMap
Definition __HASHMAP.h:92
Iterator & operator=(const Iterator &_it)
Definition __HASHMAP.h:167
Iterator & operator++()
Definition __HASHMAP.cpp:46
HashNode * __pNode
Definition __HASHMAP.h:93
Iterator find(const KEY_T &_key)
const HASHMAP_T & operator=(const HASHMAP_T &_src)
size_t bucketSize() const
Definition __HASHMAP.h:278
size_t bucketIndex(const KEY_T &_key) const
size_t erase(const KEY_T &_key)
ConstIterator begin() const
friend class ConstIterator
Definition __HASHMAP.h:148
void initBuckets(size_t _bucketSize)
HASHMAP_T(size_t _bucketSize=21)
VALUE_T & operator[](const KEY_T &_key)
ConstIterator end() const
Definition __HASHMAP.h:271
bool isEmpty() const
Definition __HASHMAP.h:292
size_t __size
Definition __HASHMAP.h:144
HASHFUN_T __hashFun
Definition __HASHMAP.h:143
friend class Iterator
Definition __HASHMAP.h:147
size_t sizeOfBucket(size_t _index) const
virtual ~HASHMAP_T()
HashNode * createNode(const KEY_T &_key)
void destroyNode(HashNode *_pNode)
size_t size() const
Definition __HASHMAP.h:285
bool lookup(const KEY_T &_key, VALUE_T &_rValue) const
PointerArray __buckets
Definition __HASHMAP.h:145
Object()
Definition Object.cpp:183
virtual String toString() const
Definition Object.cpp:187
Assoc(const KEY_T &_key, const VALUE_T &_value)
Definition __HASHMAP.h:68
HashNode * pNext
Definition __HASHMAP.h:77