47template <
class T,
class U,
class TAlloc = TDefaultAllocator<T>>
56 static constexpr unsigned int UnsetNode = 999999999;
87 void insert(
const T &key,
const U &value);
97 bool hasKey(
const T &key)
const;
103 bool getValue(
const T &key, U &value)
const;
122 void append(T key,
const U &value);
127 Node **mBuffer{
nullptr};
128 size_t mNumItems{0u};
129 size_t mBuffersize{0u};
132template <
class T,
class U,
class TAlloc>
137template <
class T,
class U,
class TAlloc>
142template <
class T,
class U,
class TAlloc>
147template <
class T,
class U,
class TAlloc>
152template <
class T,
class U,
class TAlloc>
154 return (0u == mNumItems);
157template <
class T,
class U,
class TAlloc>
159 mBuffer =
new Node *[
init];
160 for (
size_t i = 0; i <
init; i++) {
161 mBuffer[i] =
nullptr;
166template <
class T,
class U,
class TAlloc>
168 for (
size_t i = 0; i < mBuffersize; ++i) {
169 if (
nullptr != mBuffer[i]) {
170 mBuffer[i]->releaseList();
179template <
class T,
class U,
class TAlloc>
181 const T hash =
Hash::toHash(key,
static_cast<T
>(mBuffersize));
182 if (
nullptr == mBuffer[hash]) {
183 Node *node =
new Node;
185 node->mValue = value;
186 mBuffer[hash] = node;
188 mBuffer[hash]->append(key, value);
193template <
class T,
class U,
class TAlloc>
195 const T hash =
Hash::toHash(key,
static_cast<unsigned int>(mBuffersize));
196 if (
nullptr == mBuffer[hash]) {
201 Node *current = mBuffer[hash];
202 if (current->mKey == key) {
203 Node *next = current->mNext;
204 mBuffer[hash] = next;
211 found = current->remove(key);
219template <
class T,
class U,
class TAlloc>
222 if (0 == mBuffersize) {
226 const Node *node = mBuffer[hash];
227 if (
nullptr == node) {
231 if (node->mKey == key) {
235 if (
nullptr != node->mNext) {
236 Node *next = node->mNext;
237 while (
nullptr != next) {
238 if (next->mKey == key) {
248template <
class T,
class U,
class TAlloc>
250 const size_t pos =
Hash::toHash(key, (
unsigned int) mBuffersize);
251 if (mBuffer[pos]->mKey == key) {
252 value = mBuffer[pos]->mValue;
256 Node *node = mBuffer[pos];
257 Node *next = node->mNext;
258 while (next->mKey != key) {
260 if (
nullptr == next) {
264 value = next->mValue;
269template <
class T,
class U,
class TAlloc>
272 const unsigned int pos =
Hash::toHash(key, mBuffersize);
273 if (mBuffer[pos]->mKey == key) {
274 return mBuffer[pos]->mValue;
277 Node *next = mBuffer[pos]->mNext;
278 while (next->mKey != key) {
280 if (
nullptr == next) {
288template <
class T,
class U,
class TAlloc>
289inline THashMap<T, U, TAlloc>::Node::Node() :
295template <
class T,
class U,
class TAlloc>
296inline void THashMap<T, U, TAlloc>::Node::append(T key,
const U &value) {
303 Node *current = mNext;
304 if (
nullptr != current) {
306 while (current->mNext) {
307 current = current->mNext;
309 current->mNext =
new Node;
310 current->mNext->mKey = key;
311 current->mNext->mValue = value;
317 current->mValue = value;
321template <
class T,
class U,
class TAlloc>
323 if (
nullptr == mNext) {
328 Node *current = mNext, *prev =
nullptr;
329 while (
nullptr != current) {
330 if (current->mKey == key) {
331 if (
nullptr != prev) {
332 prev->mNext = current->mNext;
339 current = current->mNext;
345template <
class T,
class U,
class TAlloc>
347 if (
nullptr == mNext) {
351 Node *current = mNext;
352 while (
nullptr != current) {
354 current = current->mNext;
This class is used to calculate the hash value for a given integer or character buffer.
static T toHash(const char *buffer, T base)
Computes the hash value for a given character buffer.
static constexpr size_t InitSize
The initial hash size.
bool hasKey(const T &key) const
Looks for a given key and returns true, if a key-value pair is stored in the list.
bool isEmpty() const
Will return true, if hash-map is empty.
void insert(const T &key, const U &value)
A new key value pair will be entered.
U & operator[](const T &key) const
Returns the assigned value for the given key.
bool remove(const T &key)
Will remove a given key-value pair form the hash-map.
THashMap(size_t init=InitSize)
The class constructor.
bool getValue(const T &key, U &value) const
Returns the assigned value for the given key.
size_t size() const
Returns the number of stored items in the hash-map.
size_t capacity() const
Will return the number of possible hash items stored in the hash map.
THashMap< T, U, TAlloc > & operator=(const THashMap< T, U > &)=delete
void clear()
The hash-map will be cleared.
THash< T > Hash
The alias.
static constexpr unsigned int UnsetNode
Marker for unset node keys.
~THashMap()
The class destructor.
void init(size_t init)
Will init the hash-map with the given size.