Elm  2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
HashMap< K, T, H, A, E > Class Template Reference

#include <elm/data/HashMap.h>

+ Inheritance diagram for HashMap< K, T, H, A, E >:

Classes

class  Iter
 
class  KeyIter
 
class  PairIter
 

Public Types

typedef K key_t
 
typedef T val_t
 
typedef HashMap< K, T, H, A, E > self_t
 
- Public Types inherited from Equiv< T >
typedef T t
 

Public Member Functions

 HashMap (int _size=211)
 
 HashMap (const self_t &h)
 
const H & hash () const
 
H & hash ()
 
const A & allocator () const
 
A & allocator ()
 
const E & equivalence () const
 
E & equivalence ()
 
void clear (void)
 
void add (const K &key, const T &val)
 
T & fetch (const K &k)
 
Option< T > get (const K &k) const
 
const T & get (const K &k, const T &def) const
 
bool hasKey (const K &k) const
 
Option< T > get_const (const K &k) const
 
const T & get_const (const K &k, const T &def) const
 
bool hasKey_const (const K &k) const
 
Iterable< KeyIterkeys () const
 
Iterable< PairIterpairs () const
 
int count () const
 
bool isEmpty () const
 
 operator bool () const
 
Iter begin (void) const
 
Iter end (void) const
 
bool contains (const T &item) const
 
template<class C >
bool containsAll (const C &c) const
 
bool equals (const HashMap< K, T > &t) const
 
bool operator== (const HashMap< K, T > &t) const
 
bool operator!= (const HashMap< K, T > &t) const
 
bool includes (const HashMap< K, T > &t) const
 
bool operator<= (const HashMap< K, T > &t) const
 
bool operator>= (const HashMap< K, T > &t) const
 
bool operator< (const HashMap< K, T > &t) const
 
bool operator> (const HashMap< K, T > &t) const
 
void put (const K &key, const T &val)
 
void remove (const K &k)
 
void remove (const Iter &i)
 
const T & operator[] (const K &k) const
 
StrictMapDelegate< self_toperator[] (const K &key)
 
const T & operator[] (const Iter &i) const
 
StrictMapDelegate< self_toperator[] (const Iter &i)
 
template<class C >
void putAll (const C &c)
 
int minEntry (void) const
 
int maxEntry (void) const
 
int zeroEntry (void) const
 
int size (void) const
 
bool exists (const K &k) const
 
Iter operator* (void) const
 
- Public Member Functions inherited from Equiv< T >
bool isEqual (const T &v1, const T &v2) const
 

Additional Inherited Members

- Static Public Member Functions inherited from Equiv< T >
static bool equals (const T &v1, const T &v2)
 
- Static Public Attributes inherited from Equiv< T >
static Equiv< T > def
 

Detailed Description

template<class K, class T, class H = HashKey<K>, class A = DefaultAlloc, class E = Equiv<T>>
class elm::HashMap< K, T, H, A, E >

Map implemented using an hash table.

Implemented Concepts
  • Collection
  • Map
  • MutableMap
Characteristics
S is the size of the table.
  • average access time: O(n / S)
  • average add time: O(n / S)
  • average remove time: O(n / S)
  • memory space: pointer size * S + n * (key size + value size + pointer size)
Parameters
KType of the key.
TType of values.
MUsed manager (default to HashManager).

Member Typedef Documentation

◆ key_t

typedef K key_t

◆ self_t

typedef HashMap<K, T, H, A, E> self_t

◆ val_t

typedef T val_t

Constructor & Destructor Documentation

◆ HashMap() [1/2]

HashMap ( int  size = 211)
inline

Build an hash map with the given size. Improved efficiency is obtained with prime number as sizes.

Parameters
sizeTable size (default to 211).

◆ HashMap() [2/2]

HashMap ( const self_t h)
inline

Member Function Documentation

◆ add()

void add ( const K &  key,
const T &  val 
)
inline

◆ allocator() [1/2]

A& allocator ( )
inline

◆ allocator() [2/2]

const A& allocator ( ) const
inline

◆ begin()

Iter begin ( void  ) const
inline

◆ clear()

void clear ( void  )
inline

Remove all items of the map.

Referenced by TextSerializer::flush().

◆ contains()

◆ containsAll()

bool containsAll ( const C &  c) const
inline

Test if all items of collection c are in the map.

Parameters
cCollection to test.
Returns
True if all collection items are in the map, false else.

Referenced by HashMap< elm::CString, void * >::equals(), and HashMap< elm::CString, void * >::includes().

◆ count()

int count ( ) const
inline

Count the number of items in the map.

Returns
Count of items.

◆ end()

Iter end ( void  ) const
inline

◆ equals()

◆ equivalence() [1/2]

E& equivalence ( )
inline

◆ equivalence() [2/2]

const E& equivalence ( ) const
inline

◆ exists()

bool exists ( const K &  k) const
inline

Same as hasKey().

Referenced by TextSerializer::onPointer().

◆ fetch()

T & fetch ( const K &  k)
inline

Get a reference to the data stored with the key k. If no data is already associated with key k, an entry and corresponding data are created and returns a reference to it.

Parameters
kKey of looked data.
Returns
Reference to data associated with key.

◆ get() [1/2]

Option< T > get ( const K &  key) const
inline

Get an item by its key.

Parameters
keyLooked key.
Returns
The matching value if the key is in the map, none else.

Referenced by TextSerializer::flush(), and XOMUnserializer::flush().

◆ get() [2/2]

const T & get ( const K &  key,
const T &  def 
) const
inline

Get an item by its key.

Parameters
keyLooked key.
defDefault value.
Returns
The matching value if the key is in the map, the default value else.

◆ get_const() [1/2]

Option<T> get_const ( const K &  k) const
inline

◆ get_const() [2/2]

const T& get_const ( const K &  k,
const T &  def 
) const
inline

◆ hash() [1/2]

H& hash ( )
inline

◆ hash() [2/2]

const H& hash ( ) const
inline

◆ hasKey()

bool hasKey ( const K &  k) const
inline

Test if a key is in the map.

Parameters
keyTested key.
Returns
True if there is an item in the map with the given key, false else.

Referenced by HashMap< elm::CString, void * >::exists(), and XOMElementSerializer::onPointer().

◆ hasKey_const()

bool hasKey_const ( const K &  k) const
inline

◆ includes()

bool includes ( const HashMap< K, T > &  t) const
inline

◆ isEmpty()

bool isEmpty ( ) const
inline

Test if the map is empty.

Returns
True if the map is empty, false else.

Referenced by HashMap< elm::CString, void * >::operator bool().

◆ keys()

Iterable<KeyIter> keys ( ) const
inline

◆ maxEntry()

int maxEntry ( void  ) const
inline

◆ minEntry()

int minEntry ( void  ) const
inline

◆ operator bool()

operator bool ( ) const
inline

◆ operator!=()

bool operator!= ( const HashMap< K, T > &  t) const
inline

◆ operator*()

Iter operator* ( void  ) const
inline

◆ operator<()

bool operator< ( const HashMap< K, T > &  t) const
inline

◆ operator<=()

bool operator<= ( const HashMap< K, T > &  t) const
inline

◆ operator==()

bool operator== ( const HashMap< K, T > &  t) const
inline

◆ operator>()

bool operator> ( const HashMap< K, T > &  t) const
inline

◆ operator>=()

bool operator>= ( const HashMap< K, T > &  t) const
inline

◆ operator[]() [1/4]

StrictMapDelegate<self_t> operator[] ( const Iter i)
inline

◆ operator[]() [2/4]

const T& operator[] ( const Iter i) const
inline

◆ operator[]() [3/4]

const T& operator[] ( const K &  k) const
inline

◆ operator[]() [4/4]

StrictMapDelegate<self_t> operator[] ( const K &  key)
inline

◆ pairs()

Iterable<PairIter> pairs ( ) const
inline

◆ put()

void put ( const K &  key,
const T &  val 
)
inline

Put a new item in the map matching the given key.

Parameters
keyKey of added item.
valAdded item.

Referenced by XOMUnserializer::flush(), TextSerializer::onPointer(), XOMElementSerializer::onPointer(), and HashMap< elm::CString, void * >::putAll().

◆ putAll()

void putAll ( const C &  c)
inline

◆ remove() [1/2]

void remove ( const Iter i)
inline

◆ remove() [2/2]

void remove ( const K &  key)
inline

Remove an item by its key.

Parameters
keyKey of the removed item.

◆ size()

int size ( void  ) const
inline

◆ zeroEntry()

int zeroEntry ( void  ) const
inline

The documentation for this class was generated from the following files: