DCL 4.0
Loading...
Searching...
No Matches
HASHMAP_T Class Reference

#include <__HASHMAP.h>

Inheritance diagram for HASHMAP_T:
Object

Classes

struct  Assoc
class  ConstIterator
struct  HashNode
class  Iterator

Public Member Functions

virtual ~HASHMAP_T ()
 HASHMAP_T (size_t _bucketSize=21)
void initBuckets (size_t _bucketSize)
 HASHMAP_T (const HASHMAP_T &_src)
const HASHMAP_Toperator= (const HASHMAP_T &_src)
ConstIterator begin () const
ConstIterator end () const
Iterator begin ()
Iterator end ()
size_t bucketSize () const
size_t size () const
size_t sizeOfBucket (size_t _index) const
bool isEmpty () const
Iterator find (const KEY_T &_key)
ConstIterator find (const KEY_T &_key) const
bool lookup (const KEY_T &_key, VALUE_T &_rValue) const
VALUE_T & operator[] (const KEY_T &_key)
size_t erase (const KEY_T &_key)
void clear ()
Public Member Functions inherited from Object
virtual String toString () const
virtual void destroy ()
String className () const
bool isInstanceOf (const std::type_info &typeinfo) const
virtual const std::type_info & typeInfo () const

Protected Member Functions

size_t bucketIndex (const KEY_T &_key) const
HashNodecreateNode (const KEY_T &_key)
void destroyNode (HashNode *_pNode)
Protected Member Functions inherited from Object
virtual ~Object ()
 Object ()

Protected Attributes

HASHFUN_T __hashFun
size_t __size
PointerArray __buckets

Friends

class Iterator
class ConstIterator

Detailed Description

template class HashMap의 DSO 호환성을 제공한다.

C++의 template class는 해당 코드를 사용하기 전에는 실제 이진 코드를 생성하지 않으므로, DSO(so, DLL)와 DSO, 또는 실행파일에서 객체를 주고받을 수 없다.

이 클래스는 DSO의 이러한 문제를 해결하며, 포함파일은 <dcl/HashMap.h>이다.

이 코드를 사용하는 클래스는 다음과 같다.

  • class DCLCAPI StringToStringMap
  • class DCLCAPI StringToPointerMap
  • class DCLCAPI IntToIntMap
See also
HashMap

Definition at line 55 of file __HASHMAP.h.

Constructor & Destructor Documentation

◆ ~HASHMAP_T()

virtual HASHMAP_T::~HASHMAP_T ( )
virtual

◆ HASHMAP_T() [1/2]

HASHMAP_T::HASHMAP_T ( size_t _bucketSize = 21)

Definition at line 127 of file __HASHMAP.cpp.

128 : __buckets(DCLGetNextPrimNumber(_bucketSize))
129{
130 __size = 0;
131// __buckets.resize(DCLGetNextPrimNumber(_bucketSize));
132}
DCLCAPI size_t DCLGetNextPrimNumber(size_t _n)
Definition HashFun.cpp:23
size_t __size
Definition __HASHMAP.h:144
PointerArray __buckets
Definition __HASHMAP.h:145

◆ HASHMAP_T() [2/2]

HASHMAP_T::HASHMAP_T ( const HASHMAP_T & _src)

Definition at line 140 of file __HASHMAP.cpp.

141{
142 *this = _src;
143}

Member Function Documentation

◆ begin() [1/2]

HASHMAP_T::Iterator HASHMAP_T::begin ( )

Definition at line 186 of file __HASHMAP.cpp.

187{
188 for(size_t i = 0; i < __buckets.size(); i++)
189 {
190 if (__buckets[i] != NULL)
191 return Iterator((HashNode*)__buckets[i], this);
192 }
193 return Iterator(NULL, this);
194}
#define NULL
Definition Config.h:340
friend class Iterator
Definition __HASHMAP.h:147

◆ begin() [2/2]

HASHMAP_T::ConstIterator HASHMAP_T::begin ( ) const

Definition at line 175 of file __HASHMAP.cpp.

176{
177 for(size_t i = 0; i < __buckets.size(); i++)
178 {
179 if (__buckets[i] != NULL)
180 return ConstIterator((HashNode*)__buckets[i], this);
181 }
182 return ConstIterator(NULL, this);
183}
friend class ConstIterator
Definition __HASHMAP.h:148

◆ bucketIndex()

size_t HASHMAP_T::bucketIndex ( const KEY_T & _key) const
inlineprotected

Definition at line 272 of file __HASHMAP.cpp.

273{
274 return __hashFun.hashKey(_key) % __buckets.size();
275}
HASHFUN_T __hashFun
Definition __HASHMAP.h:143

◆ bucketSize()

size_t HASHMAP_T::bucketSize ( ) const
inline

Definition at line 278 of file __HASHMAP.h.

279{
280 return __buckets.size();
281}

◆ clear()

void HASHMAP_T::clear ( )

Definition at line 359 of file __HASHMAP.cpp.

360{
361 for(size_t i = 0; i < __buckets.size(); i++)
362 {
363 HashNode* pNode = (HashNode*)__buckets[i];
364 while(pNode)
365 {
366 HashNode* pNext = pNode->pNext;
367 destroyNode(pNode);
368 pNode = pNext;
369 }
370 __buckets[i] = NULL;
371 }
372 __size = 0;
373}
void destroyNode(HashNode *_pNode)
HashNode * pNext
Definition __HASHMAP.h:77

◆ createNode()

HASHMAP_T::HashNode * HASHMAP_T::createNode ( const KEY_T & _key)
protected

Definition at line 278 of file __HASHMAP.cpp.

279{
280 HashNode* pNode = (HashNode*) malloc(sizeof(HashNode));
281 // FIXME!
282 // if (pNode == NULL)
283 // throw new BadAllocException(sizeof(HashNode), __THIS_FILE__, __LINE__);
284 __DCL_ASSERT(pNode != NULL);
285
286 memset((void*) pNode, 0, sizeof(HashNode));
287
288#if __DCL_HAVE_ALLOC_DEBUG
289#undef new
290#endif
291
292#if HAVE_CONSTRUCTOR_KEY
293 new(&(pNode->key)) KEY_T;
294#endif
295#if HAVE_CONSTRUCTOR_VALUE
296 new(&(pNode->value)) VALUE_T;
297#endif
298
299#if __DCL_HAVE_ALLOC_DEBUG
300#define new __DCL_DEBUG_NEW
301#endif
302
303 pNode->key = _key;
304 return pNode;
305}
#define __DCL_ASSERT(expr)
Definition Object.h:371

◆ destroyNode()

void HASHMAP_T::destroyNode ( HashNode * _pNode)
protected

Definition at line 308 of file __HASHMAP.cpp.

309{
310#if HAVE_CONSTRUCTOR_KEY
311 _pNode->key.~KEY_T();
312#endif
313#if HAVE_CONSTRUCTOR_VALUE
314 _pNode->value.~VALUE_T();
315#endif
316 free(_pNode);
317}

◆ end() [1/2]

HASHMAP_T::Iterator HASHMAP_T::end ( )
inline

Definition at line 264 of file __HASHMAP.h.

265{
266 return Iterator(NULL, this);
267}

◆ end() [2/2]

HASHMAP_T::ConstIterator HASHMAP_T::end ( ) const
inline

Definition at line 271 of file __HASHMAP.h.

272{
273 return ConstIterator(NULL, this);
274}

◆ erase()

size_t HASHMAP_T::erase ( const KEY_T & _key)

Definition at line 320 of file __HASHMAP.cpp.

321{
322 size_t nErased = 0;
323 size_t index = bucketIndex(_key);
324 HashNode* pCurrentNode = (HashNode*)__buckets[index];
325 if (pCurrentNode != NULL)
326 {
327 if (pCurrentNode->key == _key) // first
328 {
329 __buckets[index] = pCurrentNode->pNext;
330 destroyNode(pCurrentNode);
331 nErased++;
332 __size--;
333 }
334 else
335 {
336 HashNode* pNextNode = pCurrentNode->pNext;
337 while(pNextNode != NULL)
338 {
339 if (pNextNode->key == _key)
340 {
341 pCurrentNode->pNext = pNextNode->pNext;
342 destroyNode(pNextNode);
343 nErased++;
344 __size--;
345 break;
346 }
347 else
348 {
349 pCurrentNode = pNextNode;
350 pNextNode = pCurrentNode->pNext;
351 }
352 }
353 }
354 }
355 return nErased;
356}
size_t bucketIndex(const KEY_T &_key) const

◆ find() [1/2]

HASHMAP_T::Iterator HASHMAP_T::find ( const KEY_T & _key)

Definition at line 209 of file __HASHMAP.cpp.

210{
211 size_t index = bucketIndex(_key);
212 HashNode* pNode = (HashNode*)__buckets[index];
213 while (pNode) {
214 if (pNode->key == _key) {
215 break;
216 }
217 pNode = pNode->pNext;
218 }
219 return Iterator(pNode, this);
220}

◆ find() [2/2]

HASHMAP_T::ConstIterator HASHMAP_T::find ( const KEY_T & _key) const

Definition at line 223 of file __HASHMAP.cpp.

224{
225 size_t index = bucketIndex(_key);
226 const HashNode* pNode = (HashNode*)__buckets[index];
227 while (pNode) {
228 if (pNode->key == _key) {
229 break;
230 }
231 pNode = pNode->pNext;
232 }
233 return ConstIterator(pNode, this);
234}

◆ initBuckets()

void HASHMAP_T::initBuckets ( size_t _bucketSize)

Definition at line 134 of file __HASHMAP.cpp.

135{
136 clear();
137 __buckets.resize(DCLGetNextPrimNumber(_bucketSize));
138}
void clear()

◆ isEmpty()

bool HASHMAP_T::isEmpty ( ) const
inline

Definition at line 292 of file __HASHMAP.h.

293{
294 return __size == 0;
295}

◆ lookup()

bool HASHMAP_T::lookup ( const KEY_T & _key,
VALUE_T & _rValue ) const

Definition at line 237 of file __HASHMAP.cpp.

238{
239 size_t index = bucketIndex(_key);
240 HashNode* pNode = (HashNode*)__buckets[index];
241 while(pNode != NULL) {
242 if (pNode->key == _key) {
243 _rValue = pNode->value;
244 return true;
245 }
246 pNode = pNode->pNext;
247 }
248 return false;
249}

◆ operator=()

const HASHMAP_T & HASHMAP_T::operator= ( const HASHMAP_T & _src)

Definition at line 146 of file __HASHMAP.cpp.

147{
148 if (&_src != this)
149 {
150 clear();
151 __size = _src.__size;
152 __buckets.resize(_src.__buckets.size());
153
154 for(size_t index = 0; index < _src.__buckets.size(); index++)
155 {
156 const HashNode* pNode = (HashNode*) _src.__buckets[index];
157 if (pNode != NULL)
158 {
159 HashNode* pNewNode = createNode(pNode->key);
160 pNewNode->value = pNode->value;
161 __buckets[index] = pNewNode;
162 for(pNode = pNode->pNext; pNode != NULL; pNode = pNode->pNext)
163 {
164 pNewNode->pNext = createNode(pNode->key);
165 pNewNode = pNewNode->pNext;
166 pNewNode->value = pNode->value;
167 }
168 }
169 }
170 }
171 return *this;
172}
HashNode * createNode(const KEY_T &_key)

◆ operator[]()

VALUE_T & HASHMAP_T::operator[] ( const KEY_T & _key)

Definition at line 252 of file __HASHMAP.cpp.

253{
254 size_t index = bucketIndex(_key);
255 HashNode* pFirstNode = (HashNode*)__buckets[index];
256 for(HashNode* pCurrentNode = pFirstNode; pCurrentNode!= NULL;
257 pCurrentNode = pCurrentNode->pNext)
258 {
259 if (pCurrentNode->key == _key)
260 return pCurrentNode->value;
261 }
262
263 HashNode* pNewNode = createNode(_key);
264 pNewNode->pNext = pFirstNode;
265 __buckets[index] = pNewNode;
266 __size++;
267 return pNewNode->value;
268}

◆ size()

size_t HASHMAP_T::size ( ) const
inline

Definition at line 285 of file __HASHMAP.h.

286{
287 return __size;
288}

◆ sizeOfBucket()

size_t HASHMAP_T::sizeOfBucket ( size_t _index) const

Definition at line 197 of file __HASHMAP.cpp.

198{
199 __DCL_ASSERT(_index < __buckets.size());
200
201 size_t nCount = 0;
202 HashNode* pNode = (HashNode*)__buckets[_index];
203 for(; pNode != NULL; pNode = pNode->pNext)
204 nCount++;
205 return nCount;
206}

◆ ConstIterator

friend class ConstIterator
friend

Definition at line 148 of file __HASHMAP.h.

◆ Iterator

friend class Iterator
friend

Definition at line 147 of file __HASHMAP.h.

Member Data Documentation

◆ __buckets

PointerArray HASHMAP_T::__buckets
protected

Definition at line 145 of file __HASHMAP.h.

◆ __hashFun

HASHFUN_T HASHMAP_T::__hashFun
protected

Definition at line 143 of file __HASHMAP.h.

◆ __size

size_t HASHMAP_T::__size
protected

Definition at line 144 of file __HASHMAP.h.


The documentation for this class was generated from the following files: