23#ifndef BAGEL_BOFLIB_VHASH_TABLE_H
24#define BAGEL_BOFLIB_VHASH_TABLE_H
26#include "bagel/spacebar/boflib/list.h"
31template<
class T,
int S>
36 bool contains(
const T &val);
37 void insert(
const T &val);
53 unsigned(*_pHashFunction)(
const T &);
66template<
class T,
int S>
68 _pHashFunction(hashFun), _bisEmpty(true) {
72template<
class T,
int S>
73CBofVHashTable<T, S>::~CBofVHashTable() {
74 for (
int x = 0; x < _nHashTableSize; x++) {
75 CBofList<T *> *pHashBucket = &_xHashTable[x];
76 int nListEntries = pHashBucket->getActualCount();
78 for (
int i = 0; i < nListEntries; i++) {
79 T *pListItem = pHashBucket->getNodeItem(i);
81 pHashBucket->setNodeItem(i, (T *)
nullptr);
87template<
class T,
int S>
88void CBofVHashTable<T, S>::insert(
const T &val) {
89 T *pNodeValue =
new T(val);
90 CBofListNode<T *> *pNode =
new CBofListNode<T *>(pNodeValue);
91 assert(pNode !=
nullptr);
93 int nHashBucketIndex = ((*_pHashFunction)(val)) % _nHashTableSize;
94 assert(nHashBucketIndex < _nHashTableSize);
96 CBofList<T *> *pHashBucket = &_xHashTable[nHashBucketIndex];
97 assert(pHashBucket !=
nullptr);
98 pHashBucket->addToTail(pNode);
102template<
class T,
int S>
103bool CBofVHashTable<T, S>::contains(
const T &val) {
104 bool returnValue =
false;
105 int nHashBucketIndex = ((*_pHashFunction)(val)) % _nHashTableSize;
106 assert(nHashBucketIndex < _nHashTableSize);
108 CBofVHashTable<T, S> *
const fakeThis = (CBofVHashTable<T, S> *
const)
this;
109 CBofList<T *> *pHashBucket = &(fakeThis->_xHashTable[nHashBucketIndex]);
110 assert(pHashBucket !=
nullptr);
111 int nItemsInBucket = pHashBucket->getCount();
112 for (
int i = 0; i < nItemsInBucket; i++) {
113 T *TableEntry = pHashBucket->getNodeItem(i);
114 if (TableEntry->compareNoCase((
const char *)val) == 0) {
Definition: vhash_table.h:32