Clarisse 5.0 SP10 SDK 5.0.5.10.0
Loading...
Searching...
No Matches
CoreOrderedHashTable< T, U > Class Template Reference

CoreOrderedHashTable provides an implementation of a container of U based on an hash_table< T, unsigned int > and two vectors vector< U > for storing data and vector< unsigned int > to manage sorting. More...

#include <core_ordered_hash_table.h>

Classes

class  Iterator
 Provides a way to run through items as a vector. More...
 

Public Member Functions

 CoreOrderedHashTable ()
 Default Constructor. More...
 
 CoreOrderedHashTable (const CoreOrderedHashTable &dic)
 Copy constructor. More...
 
size_t get_memory_size () const
 Gets the current memory usage of the dictionary. More...
 
void add (const T &key, const U &item)
 Adds an entry in the dictionary. More...
 
void remove (const T &key)
 Removes an entry from the dictionary. More...
 
void remove_all ()
 Removes all the entries from the dictionary.
 
bool is_empty () const
 Dictionnary entries emptyness accessor. More...
 
const unsigned int & get_count () const
 Dictionnary entries count accessor. More...
 
CoreArray< T > get_keys () const
 Get all the keys from the dictionary. More...
 
U * is_key_exists (const T &key) const
 Tests the key existency in the dictionary. More...
 
CoreArray< U > get_values () const
 Get all the data of the dictionary as an array. More...
 
U & get_value (const T &key) const
 Access an item by key. More...
 
U & operator[] (const T &key)
 Access an item by key. More...
 
const U & operator[] (const T &key) const
 const Access an item by key More...
 
void move (const unsigned int &from, const unsigned int &to)
 Moves data from an index to another. More...
 
void move (const CoreArray< T > &items, const T &tgt_item, const bool add_after=true)
 Moves a set of data to a specified index. More...
 
unsigned int find_index (const T &key) const
 Retrieves the index of an item. More...
 
U & operator[] (const unsigned int &index)
 Access an item by index. More...
 
const U & operator[] (const unsigned int &index) const
 Access an item by index. More...
 
Iterator get_iterator ()
 Create an iterator from the beginning of the dictionary. More...
 
Iterator get_iterator () const
 Create an iterator from the beginning of the dictionary. More...
 

Detailed Description

template<class T, class U>
class CoreOrderedHashTable< T, U >

CoreOrderedHashTable provides an implementation of a container of U based on an hash_table< T, unsigned int > and two vectors vector< U > for storing data and vector< unsigned int > to manage sorting.

Note
This implementation performs auto-resize of the hash_table and the vectors on add/remove methods above a certain threshold, under the threshold we manage null entries in the data vector
This implementation is NOT RECOMMENDED for non pointer usage, due to null value (0) used internally to consider data entry as invalid !!!
Warning
However, if the template parameter T is specialized with a non pointer type, core_get_null_value() must be implemented for the specialized type
See also
core_get_null_value

Constructor & Destructor Documentation

◆ CoreOrderedHashTable() [1/2]

template<class T , class U >
CoreOrderedHashTable< T, U >::CoreOrderedHashTable ( )
inline

Default Constructor.

Parameters
specifiesdefault dictionary size

◆ CoreOrderedHashTable() [2/2]

template<class T , class U >
CoreOrderedHashTable< T, U >::CoreOrderedHashTable ( const CoreOrderedHashTable< T, U > &  dic)
inline

Copy constructor.

Parameters
theitem dictionary to copy

Member Function Documentation

◆ add()

template<class T , class U >
void CoreOrderedHashTable< T, U >::add ( const T &  key,
const U &  item 
)

Adds an entry in the dictionary.

Parameters
theunique key that identifies the entry
thedata associated to the entry

◆ find_index()

template<class T , class U >
unsigned int CoreOrderedHashTable< T, U >::find_index ( const T &  key) const

Retrieves the index of an item.

Parameters
thekey to retrieve
Returns
returns the index of the item if exists, -1 otherwise

◆ get_count()

template<class T , class U >
const unsigned int & CoreOrderedHashTable< T, U >::get_count ( ) const
inline

Dictionnary entries count accessor.

Returns
the count of entries in the dictionary

◆ get_iterator() [1/2]

template<class T , class U >
Iterator CoreOrderedHashTable< T, U >::get_iterator ( )
inline

Create an iterator from the beginning of the dictionary.

Returns
An iterator located on the first entry of the dictionary

◆ get_iterator() [2/2]

template<class T , class U >
Iterator CoreOrderedHashTable< T, U >::get_iterator ( ) const
inline

Create an iterator from the beginning of the dictionary.

Returns
An iterator located on the first entry of the dictionary

◆ get_keys()

template<class T , class U >
CoreArray< T > CoreOrderedHashTable< T, U >::get_keys ( ) const
inline

Get all the keys from the dictionary.

Returns
an array of keys

◆ get_memory_size()

template<class T , class U >
size_t CoreOrderedHashTable< T, U >::get_memory_size ( ) const
inline

Gets the current memory usage of the dictionary.

Returns
the sum of memory used by the implementation of the dictionary

◆ get_value()

template<class T , class U >
U & CoreOrderedHashTable< T, U >::get_value ( const T &  key) const
inline

Access an item by key.

Parameters
thekey to retrieve in the dictionary
Returns
the item associated to the key if key exists, 0 otherwise

◆ get_values()

template<class T , class U >
CoreArray< U > CoreOrderedHashTable< T, U >::get_values

Get all the data of the dictionary as an array.

Returns
an array of data

◆ is_empty()

template<class T , class U >
bool CoreOrderedHashTable< T, U >::is_empty ( ) const
inline

Dictionnary entries emptyness accessor.

Returns
true if the count of entries in the dictionary is 0

◆ is_key_exists()

template<class T , class U >
U * CoreOrderedHashTable< T, U >::is_key_exists ( const T &  key) const
inline

Tests the key existency in the dictionary.

Parameters
thekey to retrieve
Returns
a pointer on the data associated to the key if key exists, 0 otherwise

◆ move() [1/2]

template<class T , class U >
void CoreOrderedHashTable< T, U >::move ( const CoreArray< T > &  items,
const T &  tgt_item,
const bool  add_after = true 
)

Moves a set of data to a specified index.

Parameters
theset of data to move
thedata where to move the data to
booleanspecifies to add after or before the specified target

◆ move() [2/2]

template<class T , class U >
void CoreOrderedHashTable< T, U >::move ( const unsigned int &  from,
const unsigned int &  to 
)

Moves data from an index to another.

Parameters
theindex of the data to move
thenew index where to move the data to
Note
any invalid index wont perform anything
the index is consistent with the array order from get_values()

◆ operator[]() [1/4]

template<class T , class U >
U & CoreOrderedHashTable< T, U >::operator[] ( const T &  key)
inline

Access an item by key.

Parameters
thekey of the item to retrieve
Returns
the data associated to the key
Note
the key must exist in the dictionnary

◆ operator[]() [2/4]

template<class T , class U >
const U & CoreOrderedHashTable< T, U >::operator[] ( const T &  key) const
inline

const Access an item by key

Parameters
thekey of the item to retrieve
Returns
the data associated to the key
Note
the key must exist in the dictionnary

◆ operator[]() [3/4]

template<class T , class U >
U & CoreOrderedHashTable< T, U >::operator[] ( const unsigned int &  index)

Access an item by index.

Parameters
theindex of the item to access
Returns
the data associated to the key

◆ operator[]() [4/4]

template<class T , class U >
const U & CoreOrderedHashTable< T, U >::operator[] ( const unsigned int &  index) const

Access an item by index.

Parameters
theindex of the item to access
Returns
the data associated to the key

◆ remove()

template<class T , class U >
void CoreOrderedHashTable< T, U >::remove ( const T &  key)

Removes an entry from the dictionary.

Parameters
theunique key that identifies the entry