26#ifndef WATER_HASHMAP_H_INCLUDED
27#define WATER_HASHMAP_H_INCLUDED
32#include "CarlaScopeUtils.hpp"
45 int generateHash (
const int key,
const int upperLimit)
const noexcept {
return std::abs (
key) % upperLimit; }
97template <
typename KeyType,
99 class HashFunctionType = DefaultHashFunctions>
119 HashFunctionType hashFunction = HashFunctionType())
122 hashSlots.insertMultiple (0,
nullptr, numberOfSlots);
144 const CarlaScopedPointer<HashEntry> deleter (
h);
165 inline ValueType
operator[] (KeyTypeParameter keyToLookFor)
const
168 if (entry->key == keyToLookFor)
176 bool contains (KeyTypeParameter keyToLookFor)
const
179 if (entry->key == keyToLookFor)
189 for (
const HashEntry* entry =
hashSlots.getUnchecked(
i); entry !=
nullptr; entry = entry->nextEntry)
190 if (entry->value == valueToLookFor)
201 void set (KeyTypeParameter newKey, ValueTypeParameter newValue)
209 if (entry->key == newKey)
211 entry->value = newValue;
224 void remove (KeyTypeParameter keyToRemove)
230 while (entry !=
nullptr)
232 if (entry->
key == keyToRemove)
234 const CarlaScopedPointer<HashEntry> deleter (entry);
238 if (previous !=
nullptr)
261 while (entry !=
nullptr)
263 if (entry->
value == valueToRemove)
265 const CarlaScopedPointer<HashEntry> deleter (entry);
269 if (previous !=
nullptr)
291 HashMap newTable (newNumberOfSlots);
294 for (
const HashEntry* entry =
hashSlots.getUnchecked(
i); entry !=
nullptr; entry = entry->nextEntry)
295 newTable.
set (entry->key, entry->value);
311 template <
class OtherHashMapType>
312 void swapWith (OtherHashMapType& otherHashMap)
noexcept
314 hashSlots.swapWith (otherHashMap.hashSlots);
374 if (
entry !=
nullptr)
377 while (
entry ==
nullptr)
393 return entry !=
nullptr ?
entry->key : KeyType();
401 return entry !=
nullptr ?
entry->value : ValueType();
447 CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (
HashMap)
#define CARLA_DECLARE_NON_COPYABLE(ClassName)
Definition CarlaDefines.h:242
#define noexcept
Definition DistrhoDefines.h:72
const KeyType key
Definition HashMap.h:327
HashEntry(KeyTypeParameter k, ValueTypeParameter val, HashEntry *const next)
Definition HashMap.h:323
HashEntry * nextEntry
Definition HashMap.h:329
ValueType value
Definition HashMap.h:328
int getNumSlots() const noexcept
Definition HashMap.h:304
HashFunctionType hashFunctionToUse
Definition HashMap.h:436
bool containsValue(ValueTypeParameter valueToLookFor) const
Definition HashMap.h:186
void swapWith(OtherHashMapType &otherHashMap) noexcept
Definition HashMap.h:312
void set(KeyTypeParameter newKey, ValueTypeParameter newValue)
Definition HashMap.h:201
@ defaultHashTableSize
Definition HashMap.h:433
void remapTable(int newNumberOfSlots)
Definition HashMap.h:289
ValueType operator[](KeyTypeParameter keyToLookFor) const
Definition HashMap.h:165
int totalNumItems
Definition HashMap.h:438
bool contains(KeyTypeParameter keyToLookFor) const
Definition HashMap.h:176
void removeValue(ValueTypeParameter valueToRemove)
Definition HashMap.h:254
~HashMap()
Definition HashMap.h:126
int generateHashFor(KeyTypeParameter key) const
Definition HashMap.h:440
Iterator end() const noexcept
Definition HashMap.h:429
Iterator begin() const noexcept
Definition HashMap.h:426
Array< HashEntry * > hashSlots
Definition HashMap.h:437
void clear()
Definition HashMap.h:136
HashMap(int numberOfSlots=defaultHashTableSize, HashFunctionType hashFunction=HashFunctionType())
Definition HashMap.h:118
typedef PARAMETER_TYPE(KeyType) KeyTypeParameter
typedef PARAMETER_TYPE(ValueType) ValueTypeParameter
int size() const noexcept
Definition HashMap.h:156
void remove(KeyTypeParameter keyToRemove)
Definition HashMap.h:224
register unsigned k
Definition inflate.c:946
register unsigned i
Definition inflate.c:1575
int val
Definition jpeglib.h:956
#define wassert(expression)
Definition AudioSampleBuffer.h:33
unsigned int uint32
Definition water.h:98
bool isPositiveAndBelow(Type valueToTest, Type upperLimit) noexcept
Definition MathsFunctions.h:187
long long int64
Definition water.h:100
unsigned int pointer_sized_uint
Definition water.h:113
int generateHash(const String &key, const int upperLimit) const noexcept
Definition HashMap.h:49
int generateHash(const int key, const int upperLimit) const noexcept
Definition HashMap.h:45
int generateHash(const int64 key, const int upperLimit) const noexcept
Definition HashMap.h:47
int generateHash(const void *key, const int upperLimit) const noexcept
Definition HashMap.h:51
int index
Definition HashMap.h:420
void resetToEnd() noexcept
Definition HashMap.h:414
Iterator(const HashMap &hashMapToIterate) noexcept
Definition HashMap.h:360
bool next() noexcept
Definition HashMap.h:372
ValueType getValue() const
Definition HashMap.h:399
HashEntry * entry
Definition HashMap.h:419
ValueType operator*() const
Definition HashMap.h:412
const HashMap & hashMap
Definition HashMap.h:418
Iterator(const Iterator &other) noexcept
Definition HashMap.h:364
Iterator & operator++() noexcept
Definition HashMap.h:411
void reset() noexcept
Definition HashMap.h:405
bool operator!=(const Iterator &other) const noexcept
Definition HashMap.h:413
KeyType getKey() const
Definition HashMap.h:391
ZCONST char * key
Definition crypt.c:587
uch h[RAND_HEAD_LEN]
Definition crypt.c:459
#define const
Definition zconf.h:137