Class SBCContainerHashMap#
template <class KeyType, class ValueType, class HashMapFunctor, class KeyComparator>
ClassList > SBCContainerHashMap
This template class describes a hashtable-based map. More...
#include <SBCContainerHashMap.hpp>
Classes#
Type | Name |
---|---|
class | const_iterator |
class | iterator |
Public Functions#
Type | Name |
---|---|
SBCContainerHashMap (unsigned int nElements=0) Creates a new hash map. |
|
SBCContainerHashMap (const SBCContainerHashMap & hashMap) Copy constructor. |
|
SBCContainerHashMap (SBCContainerHashMap && hashMap) Move constructor. |
|
iterator | begin () Returns an iterator that points to the beginning of the hash map. |
const_iterator | begin () const Returns an iterator that points to the beginning of the hash map. |
void | clear () Erases all entries in the hash map. |
bool | empty () const Returns true when the hash map contains no entry. |
iterator | end () Returns an iterator that points to the end of the hash map. |
const_iterator | end () const Returns an iterator that points to the end of the hash map. |
bool | erase (const KeyType & key) Attempts to erase an entry with a specific key and returns true if successful. |
iterator | find (const KeyType & key) Finds a key in the hash map. |
const_iterator | find (const KeyType & key) const Finds a key in the hash map. |
unsigned int | getMemoryFootprint () const Returns the memory footprint of the hash map. |
bool | getValue (const KeyType & key, ValueType & value) const Returns true if the key has an associated value and puts it in the__value , else returns false. |
std::optional< ValueType > | getValue (const KeyType & key) const Returns the value associated to the key if found. |
bool | hasValue (const KeyType & key) const Returns true if the key has an associated value. |
SBCContainerHashMapEntry< KeyType, ValueType > * | insert (const KeyType & key, const ValueType & value) Inserts an element in the hash map. |
SBCContainerHashMap & | operator= (const SBCContainerHashMap & hashMap) Copy assignment. |
SBCContainerHashMap & | operator= (SBCContainerHashMap && hashMap) Move assignment. |
ValueType & | operator[] (const KeyType & key) Returns a reference to the value mapped to the key, which is inserted if necessary. |
unsigned int | size () const The number of entries in the hash map. |
std::map< KeyType, ValueType > | toStdMap () const Returns a std map containing the same (key, value) pairs. |
virtual | ~SBCContainerHashMap () Deletes the hash map. |
Protected Attributes#
Type | Name |
---|---|
SBCContainerVector< SBCContainerHashMapEntry< KeyType, ValueType > * > * | hashMap The hash table. |
unsigned int | numberOfEntries The number of entries in the hash map. |
Detailed Description#
Parameters:
KeyType
The type of keysValueType
The type of valuesHashMapFunctor
The hash map functor, used to hash keys (by default, this is a SBCContainerHashMapFunctor<KeyType>)KeyComparator
The key comparator, used to compare keys (by default, this is a SBCContainerHashMapKeyComparator<KeyType>)
This template class describes a hashtable-based map. This container is used for example to index objects (see SBCContainerIndexer), and may be used to efficiently map keys to values:
SBVector<SBAtom*> v;
SBHashMap<SBAtom*, unsigned int> h;
// create atoms and map them to integers
for (unsigned int i = 0; i<10; i++) {
v.push_back(new SBAtom(SBElement::Carbon));
h.insert(v[i], 6 * i + 17)
}
// print integers associated to atoms
unsigned int j = 0;
for (unsigned int i = 0; i < 10; i++)
if (h.getValue(v[i], j)) std::cout << j << '\n';
Short name: SBHashMap
See also: SB_FOR
Public Functions Documentation#
function SBCContainerHashMap [1/3]#
Creates a new hash map.
function SBCContainerHashMap [2/3]#
Copy constructor.
function SBCContainerHashMap [3/3]#
Move constructor.
function begin [1/2]#
Returns an iterator that points to the beginning of the hash map.
function begin [2/2]#
Returns an iterator that points to the beginning of the hash map.
function clear#
Erases all entries in the hash map.
function empty#
Returns true when the hash map contains no entry.
function end [1/2]#
Returns an iterator that points to the end of the hash map.
function end [2/2]#
Returns an iterator that points to the end of the hash map.
function erase#
Attempts to erase an entry with a specific key and returns true if successful.
function find [1/2]#
Finds a key in the hash map.
function find [2/2]#
Finds a key in the hash map.
function getMemoryFootprint#
Returns the memory footprint of the hash map.
function getValue [1/2]#
Returns true if the key has an associated value and puts it in the__value , else returns false.
function getValue [2/2]#
Returns the value associated to the key if found.
function hasValue#
Returns true if the key has an associated value.
function insert#
Inserts an element in the hash map.
SBCContainerHashMapEntry< KeyType, ValueType > * SBCContainerHashMap::insert (
const KeyType & key,
const ValueType & value
)
function operator=#
Copy assignment.
function operator=#
Move assignment.
function operator[]#
Returns a reference to the value mapped to the key, which is inserted if necessary.
function size#
The number of entries in the hash map.
function toStdMap#
Returns a std map containing the same (key, value) pairs.
function ~SBCContainerHashMap#
Deletes the hash map.
Protected Attributes Documentation#
variable hashMap#
The hash table.
variable numberOfEntries#
The number of entries in the hash map.