106 using KeyTypeParameter =
typename TypeHelpers::ParameterType<KeyType>::type;
107 using ValueTypeParameter =
typename TypeHelpers::ParameterType<ValueType>::type;
143 for (
auto i = hashSlots.
size(); --i >= 0;)
153 hashSlots.
set (i,
nullptr);
163 return totalNumItems;
220 for (
auto* entry = hashSlots.
getUnchecked (i); entry !=
nullptr; entry = entry->nextEntry)
242 while (entry !=
nullptr)
248 entry = entry->nextEntry;
260 entry = entry->nextEntry;
275 while (entry !=
nullptr)
281 entry = entry->nextEntry;
286 hashSlots.
set (i, entry);
293 entry = entry->nextEntry;
312 HashEntry* nextEntry =
nullptr;
314 for (
auto* entry = hashSlots.
getUnchecked (i); entry !=
nullptr; entry = nextEntry)
318 nextEntry = entry->nextEntry;
334 return hashSlots.
size();
339 template <
class OtherHashMapType>
364 HashEntry (KeyTypeParameter k, ValueTypeParameter
val, HashEntry*
const next)
365 : key (k), value (
val), nextEntry (next)
370 HashEntry* nextEntry;
415 if (entry !=
nullptr)
416 entry = entry->nextEntry;
418 while (entry ==
nullptr)
434 return entry !=
nullptr ? entry->key :
KeyType();
442 return entry !=
nullptr ? entry->value : ValueType();
452 Iterator& operator++() noexcept {
next();
return *
this; }
453 ValueType operator*()
const {
return getValue(); }
454 bool operator!= (
const Iterator&
other)
const noexcept {
return entry !=
other.entry || index !=
other.index; }
455 void resetToEnd() noexcept { index = hashMap.
getNumSlots(); }
459 const HashMap& hashMap;
464 Iterator& operator= (
const Iterator&) =
delete;
477 enum { defaultHashTableSize = 101 };
478 friend struct Iterator;
481 Array<HashEntry*> hashSlots;
482 int totalNumItems = 0;
485 int generateHashFor (KeyTypeParameter key,
int numSlots)
const
487 const int hash = hashFunctionToUse.generateHash (key,
numSlots);
494 for (
auto* entry =
firstEntry; entry !=
nullptr; entry = entry->nextEntry)
501 inline HashEntry* getSlot (
KeyType key)
const noexcept {
return hashSlots.getUnchecked (generateHashFor (key,
getNumSlots())); }
Holds a resizable array of primitive or copy-by-value objects.
void swapWith(OtherArrayType &otherArray) noexcept
This swaps the contents of this array with those of another array.
ElementType getUnchecked(int index) const
Returns one of the elements in the array, without checking the index passed in.
int size() const noexcept
Returns the current number of elements in the array.
void set(int indexToChange, ParameterType newValue)
Replaces an element with a new value.
void insertMultiple(int indexToInsertAt, ParameterType newElement, int numberOfTimesToInsertIt)
Inserts multiple copies of an element into the array at a given position.
Holds a set of mappings between some key/value pairs.
int getNumSlots() const noexcept
Returns the number of slots which are available for hashing.
bool containsValue(ValueTypeParameter valueToLookFor) const
Returns true if the hash contains at least one occurrence of a given value.
const TypeOfCriticalSectionToUse & getLock() const noexcept
Returns the CriticalSection that locks this structure.
Iterator begin() const noexcept
Returns a start iterator for the values in this tree.
ValueType operator[](KeyTypeParameter keyToLookFor) const
Returns the value corresponding to a given key.
void swapWith(OtherHashMapType &otherHashMap) noexcept
Efficiently swaps the contents of two hash-maps.
void remove(KeyTypeParameter keyToRemove)
Removes an item with the given key.
void set(KeyTypeParameter newKey, ValueTypeParameter newValue)
Adds or replaces an element in the hash-map.
void remapTable(int newNumberOfSlots)
Remaps the hash-map to use a different number of slots for its hash function.
bool contains(KeyTypeParameter keyToLookFor) const
Returns true if the map contains an item with the specified key.
void removeValue(ValueTypeParameter valueToRemove)
Removes all items with the given value.
void clear()
Removes all values from the map.
typename TypeOfCriticalSectionToUse::ScopedLockType ScopedLockType
Returns the type of scoped lock to use for locking this array.
Iterator end() const noexcept
Returns an end iterator for the values in this tree.
ValueType & getReference(KeyTypeParameter keyToLookFor)
Returns a reference to the value corresponding to a given key.
int size() const noexcept
Returns the current number of items in the map.
HashMap(int numberOfSlots=defaultHashTableSize, HashFunctionType hashFunction=HashFunctionType())
Creates an empty hash-map.
A universally unique 128-bit identifier.
A variant class, that can be used to hold a range of primitive values.
#define JUCE_LEAK_DETECTOR(OwnerClass)
This macro lets you embed a leak-detecting object inside a class.
signed int int32
A platform-independent 32-bit signed integer type.
unsigned int pointer_sized_uint
An unsigned integer type that's guaranteed to be large enough to hold a pointer without truncating it...
unsigned long long uint64
A platform-independent 64-bit unsigned integer type.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
bool isPositiveAndBelow(Type1 valueToTest, Type2 upperLimit) noexcept
Returns true if a value is at least zero, and also below a specified upper limit.
unsigned int uint32
A platform-independent 32-bit unsigned integer type.
long long int64
A platform-independent 64-bit integer type.
A simple class to generate hash functions for some primitive types, intended for use with the HashMap...
static int generateHash(const void *key, int upperLimit) noexcept
Generates a simple hash from a void ptr.
static int generateHash(int32 key, int upperLimit) noexcept
Generates a simple hash from an integer.
static int generateHash(const String &key, int upperLimit) noexcept
Generates a simple hash from a string.
static int generateHash(int64 key, int upperLimit) noexcept
Generates a simple hash from an int64.
static int generateHash(uint64 key, int upperLimit) noexcept
Generates a simple hash from a uint64.
static int generateHash(const Uuid &key, int upperLimit) noexcept
Generates a simple hash from a UUID.
static int generateHash(const var &key, int upperLimit) noexcept
Generates a simple hash from a variant.
static int generateHash(uint32 key, int upperLimit) noexcept
Generates a simple hash from an unsigned int.
Iterates over the items in a HashMap.
ValueType getValue() const
Returns the current item's value.
bool next() noexcept
Moves to the next item, if one is available.
KeyType getKey() const
Returns the current item's key.
void reset() noexcept
Resets the iterator to its starting position.