Holds a set of mappings between some key/value pairs. More...
#include <juce_HashMap.h>

Classes | |
| class | HashEntry |
| struct | Iterator |
| Iterates over the items in a HashMap. More... | |
Public Types | |
| using | ScopedLockType = typename TypeOfCriticalSectionToUse::ScopedLockType |
| Returns the type of scoped lock to use for locking this array. | |
Public Member Functions | |
| HashMap (int numberOfSlots=defaultHashTableSize, HashFunctionType hashFunction=HashFunctionType()) | |
| Creates an empty hash-map. | |
| ~HashMap () | |
| Destructor. | |
| Iterator | begin () const noexcept |
| Returns a start iterator for the values in this tree. | |
| void | clear () |
| Removes all values from the map. | |
| bool | contains (KeyTypeParameter keyToLookFor) const |
| Returns true if the map contains an item with the specified key. | |
| bool | containsValue (ValueTypeParameter valueToLookFor) const |
| Returns true if the hash contains at least one occurrence of a given value. | |
| Iterator | end () const noexcept |
| Returns an end iterator for the values in this tree. | |
| const TypeOfCriticalSectionToUse & | getLock () const noexcept |
| Returns the CriticalSection that locks this structure. | |
| int | getNumSlots () const noexcept |
| Returns the number of slots which are available for hashing. | |
| ValueType & | getReference (KeyTypeParameter keyToLookFor) |
| Returns a reference to the value corresponding to a given key. | |
| ValueType | operator[] (KeyTypeParameter keyToLookFor) const |
| Returns the value corresponding to a given key. | |
| void | remapTable (int newNumberOfSlots) |
| Remaps the hash-map to use a different number of slots for its hash function. | |
| void | remove (KeyTypeParameter keyToRemove) |
| Removes an item with the given key. | |
| void | removeValue (ValueTypeParameter valueToRemove) |
| Removes all items with the given value. | |
| void | set (KeyTypeParameter newKey, ValueTypeParameter newValue) |
| Adds or replaces an element in the hash-map. | |
| int | size () const noexcept |
| Returns the current number of items in the map. | |
| template<class OtherHashMapType > | |
| void | swapWith (OtherHashMapType &otherHashMap) noexcept |
| Efficiently swaps the contents of two hash-maps. | |
Private Types | |
| enum | { defaultHashTableSize = 101 } |
| using | KeyTypeParameter = typename TypeHelpers::ParameterType< KeyType >::type |
| using | ValueTypeParameter = typename TypeHelpers::ParameterType< ValueType >::type |
Private Member Functions | |
| int | generateHashFor (KeyTypeParameter key, int numSlots) const |
| HashEntry * | getSlot (KeyType key) const noexcept |
Static Private Member Functions | |
| static HashEntry * | getEntry (HashEntry *firstEntry, KeyType keyToLookFor) noexcept |
Private Attributes | |
| HashFunctionType | hashFunctionToUse |
| Array< HashEntry * > | hashSlots |
| TypeOfCriticalSectionToUse | lock |
| int | totalNumItems = 0 |
Friends | |
| struct | Iterator |
Holds a set of mappings between some key/value pairs.
The types of the key and value objects are set as template parameters. You can also specify a class to supply a hash function that converts a key value into an hashed integer. This class must have the form:
Like the Array class, the key and value types are expected to be copy-by-value types, so if you define them to be pointer types, this class won't delete the objects that they point to.
If you don't supply a class for the HashFunctionType template parameter, the default one provides some simple mappings for strings and ints.
| HashFunctionType | The class of hash function, which must be copy-constructible. |
@tags{Core}
|
private |
| using juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::ScopedLockType = typename TypeOfCriticalSectionToUse::ScopedLockType |
Returns the type of scoped lock to use for locking this array.
|
private |
|
private |
|
inlineexplicit |
Creates an empty hash-map.
| numberOfSlots | Specifies the number of hash entries the map will use. This will be the "upperLimit" parameter that is passed to your generateHash() function. The number of hash slots will grow automatically if necessary, or it can be remapped manually using remapTable(). |
| hashFunction | An instance of HashFunctionType, which will be copied and stored to use with the HashMap. This parameter can be omitted if HashFunctionType has a default constructor. |
References juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::hashSlots.
|
inline |
Destructor.
References juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::clear().
|
inlinenoexcept |
Returns a start iterator for the values in this tree.
References juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::Iterator::next().
|
inline |
Removes all values from the map.
Note that this will clear the content, but won't affect the number of slots (see remapTable and getNumSlots).
References juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::getLock(), juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::hashSlots, and juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::totalNumItems.
Referenced by juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::~HashMap().
|
inline |
Returns true if the map contains an item with the specified key.
References juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::getEntry(), juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::getLock(), and juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::getSlot().
|
inline |
Returns true if the hash contains at least one occurrence of a given value.
References juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::getLock(), juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::getNumSlots(), and juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::hashSlots.
|
inlinenoexcept |
Returns an end iterator for the values in this tree.
References juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::Iterator::resetToEnd().
|
inlineprivate |
References juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::hashFunctionToUse, juce::isPositiveAndBelow(), and jassert.
Referenced by juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::getReference(), juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::getSlot(), juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::remapTable(), and juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::remove().
|
inlinestaticprivatenoexcept |
Referenced by juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::contains(), juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::getReference(), and juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::operator[]().
|
inlinenoexcept |
Returns the CriticalSection that locks this structure.
To lock, you can call getLock().enter() and getLock().exit(), or preferably use an object of ScopedLockType as an RAII lock for it.
References juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::lock.
Referenced by juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::clear(), juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::contains(), juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::containsValue(), juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::getReference(), juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::operator[](), juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::remapTable(), juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::remove(), juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::removeValue(), and juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::swapWith().
|
inlinenoexcept |
Returns the number of slots which are available for hashing.
Each slot corresponds to a single hash-code, and each one can contain multiple items.
References juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::hashSlots.
Referenced by juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::containsValue(), juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::getReference(), juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::getSlot(), juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::Iterator::next(), juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::remapTable(), juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::remove(), juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::removeValue(), and juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::Iterator::resetToEnd().
|
inline |
Returns a reference to the value corresponding to a given key.
If the map doesn't contain the key, a default instance of the value type is added to the map and a reference to this is returned.
| keyToLookFor | the key of the item being requested |
References juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::generateHashFor(), juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::getEntry(), juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::getLock(), juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::getNumSlots(), juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::hashSlots, juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::remapTable(), and juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::totalNumItems.
Referenced by juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::set().
|
inlineprivatenoexcept |
References juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::generateHashFor(), juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::getNumSlots(), and juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::hashSlots.
Referenced by juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::contains(), and juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::operator[]().
|
inline |
Returns the value corresponding to a given key.
If the map doesn't contain the key, a default instance of the value type is returned.
| keyToLookFor | the key of the item being requested |
References juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::getEntry(), juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::getLock(), and juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::getSlot().
|
inline |
Remaps the hash-map to use a different number of slots for its hash function.
Each slot corresponds to a single hash-code, and each one can contain multiple items.
References juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::generateHashFor(), juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::getLock(), juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::getNumSlots(), juce::Array< ElementType, TypeOfCriticalSectionToUse, minimumAllocatedSize >::getUnchecked(), juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::hashSlots, juce::Array< ElementType, TypeOfCriticalSectionToUse, minimumAllocatedSize >::insertMultiple(), and juce::Array< ElementType, TypeOfCriticalSectionToUse, minimumAllocatedSize >::set().
Referenced by juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::getReference().
|
inline |
Removes an item with the given key.
References juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::generateHashFor(), juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::getLock(), juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::getNumSlots(), juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::hashSlots, juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::HashEntry::nextEntry, and juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::totalNumItems.
|
inline |
Removes all items with the given value.
References juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::getLock(), juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::getNumSlots(), juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::hashSlots, juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::HashEntry::nextEntry, and juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::totalNumItems.
|
inline |
Adds or replaces an element in the hash-map.
If there's already an item with the given key, this will replace its value. Otherwise, a new item will be added to the map.
References juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::getReference().
|
inlinenoexcept |
Returns the current number of items in the map.
References juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::totalNumItems.
|
inlinenoexcept |
Efficiently swaps the contents of two hash-maps.
References juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::getLock(), juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::hashSlots, and juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::totalNumItems.
|
friend |
|
private |
|
private |
Referenced by juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::HashMap(), juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::clear(), juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::containsValue(), juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::getNumSlots(), juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::getReference(), juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::getSlot(), juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::Iterator::next(), juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::remapTable(), juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::remove(), juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::removeValue(), and juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::swapWith().
|
private |
|
private |
Referenced by juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::clear(), juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::getReference(), juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::remove(), juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::removeValue(), juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::size(), and juce::HashMap< KeyType, ValueType, HashFunctionType, TypeOfCriticalSectionToUse >::swapWith().