Web Analytics Made Easy - Statcounter
Skip to content

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 keys
  • ValueType The type of values
  • HashMapFunctor 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.

SBCContainerHashMap::SBCContainerHashMap (
    unsigned int nElements=0
) 


function SBCContainerHashMap [2/3]#

Copy constructor.

SBCContainerHashMap::SBCContainerHashMap (
    const SBCContainerHashMap & hashMap
) 


function SBCContainerHashMap [3/3]#

Move constructor.

SBCContainerHashMap::SBCContainerHashMap (
    SBCContainerHashMap && hashMap
) 


function begin [1/2]#

Returns an iterator that points to the beginning of the hash map.

inline iterator SBCContainerHashMap::begin () 


function begin [2/2]#

Returns an iterator that points to the beginning of the hash map.

inline const_iterator SBCContainerHashMap::begin () const


function clear#

Erases all entries in the hash map.

void SBCContainerHashMap::clear () 


function empty#

Returns true when the hash map contains no entry.

bool SBCContainerHashMap::empty () const


function end [1/2]#

Returns an iterator that points to the end of the hash map.

inline iterator SBCContainerHashMap::end () 


function end [2/2]#

Returns an iterator that points to the end of the hash map.

inline const_iterator SBCContainerHashMap::end () const


function erase#

Attempts to erase an entry with a specific key and returns true if successful.

bool SBCContainerHashMap::erase (
    const KeyType & key
) 


function find [1/2]#

Finds a key in the hash map.

inline iterator SBCContainerHashMap::find (
    const KeyType & key
) 


function find [2/2]#

Finds a key in the hash map.

inline const_iterator SBCContainerHashMap::find (
    const KeyType & key
) const


function getMemoryFootprint#

Returns the memory footprint of the hash map.

unsigned int SBCContainerHashMap::getMemoryFootprint () const


function getValue [1/2]#

Returns true if the key has an associated value and puts it in the__value , else returns false.

bool SBCContainerHashMap::getValue (
    const KeyType & key,
    ValueType & value
) const


function getValue [2/2]#

Returns the value associated to the key if found.

std::optional< ValueType > SBCContainerHashMap::getValue (
    const KeyType & key
) const


function hasValue#

Returns true if the key has an associated value.

bool SBCContainerHashMap::hasValue (
    const KeyType & key
) const


function insert#

Inserts an element in the hash map.

SBCContainerHashMapEntry< KeyType, ValueType > * SBCContainerHashMap::insert (
    const KeyType & key,
    const ValueType & value
) 


function operator=#

Copy assignment.

SBCContainerHashMap & SBCContainerHashMap::operator= (
    const SBCContainerHashMap & hashMap
) 


function operator=#

Move assignment.

SBCContainerHashMap & SBCContainerHashMap::operator= (
    SBCContainerHashMap && hashMap
) 


function operator[]#

Returns a reference to the value mapped to the key, which is inserted if necessary.

inline ValueType & SBCContainerHashMap::operator[] (
    const KeyType & key
) 


function size#

The number of entries in the hash map.

unsigned int SBCContainerHashMap::size () const


function toStdMap#

Returns a std map containing the same (key, value) pairs.

inline std::map< KeyType, ValueType > SBCContainerHashMap::toStdMap () const


function ~SBCContainerHashMap#

Deletes the hash map.

virtual SBCContainerHashMap::~SBCContainerHashMap () 


Protected Attributes Documentation#

variable hashMap#

The hash table.

SBCContainerVector<SBCContainerHashMapEntry<KeyType, ValueType>*>* hashMap;


variable numberOfEntries#

The number of entries in the hash map.

unsigned int numberOfEntries;