1 #include<HeapAllocator.h>
7 DbRetVal
HashMap::insert(void *element
)
9 HashMapNode
*newNode
= new HashMapNode();
10 newNode
->elem
= element
;
14 hashVal
= (*(int*)element
) % bucketSize
;
16 hashVal
= Util::hashBinary((char*)element
, keySize
) % bucketSize
;
17 HashMapNode
*node
= (HashMapNode
*) bucket
[hashVal
];
20 bucket
[hashVal
] = newNode
;
23 while(node
->next
!= NULL
) { node
=node
->next
; }
27 void* HashMap::find(void *element
)
30 if (optGrpIntNoNull
) {
31 int value
= *(int*)element
;
32 hashVal
= value
% bucketSize
;
33 HashMapNode
*node
= (HashMapNode
*) bucket
[hashVal
];
35 if (*(int*)node
->elem
== value
) return node
->elem
;
40 hashVal
= Util::hashBinary((char*)element
, keySize
) % bucketSize
;
41 HashMapNode
*node
= (HashMapNode
*) bucket
[hashVal
];
43 if (AllDataType::compareVal(node
->elem
, element
, OpEquals
,
51 bool HashMap::remove(void *element
)
54 HashMapNode
*delNode
=NULL
;
55 HashMapNode
*head
= NULL
, *prev
= NULL
;
56 if (optGrpIntNoNull
) {
57 int value
= *(int*)element
;
58 hashVal
= value
% bucketSize
;
59 HashMapNode
*node
= (HashMapNode
*) bucket
[hashVal
];
63 if (*(int*)node
->elem
== value
) {
65 *(long*)(&(bucket
[hashVal
])) = (long)node
->next
;
67 prev
->next
= node
->next
;
77 hashVal
= Util::hashBinary((char*)element
, keySize
) % bucketSize
;
78 HashMapNode
*node
= (HashMapNode
*) bucket
[hashVal
];
79 head
= node
; prev
= node
;
81 if (AllDataType::compareVal(node
->elem
, element
, OpEquals
,
82 typeBinary
, keySize
)) {
84 *(long*)(&(bucket
[hashVal
])) = (long)node
->next
;
86 prev
->next
= node
->next
;
98 void HashMap::removeAll()
100 for (int i
=0; i
<bucketSize
; i
++) {
101 HashMapNode
*node
=(HashMapNode
*) (bucket
[i
]);
102 HashMapNode
*prev
= NULL
;
103 while(node
!= NULL
) {