Clarisse 5.0 SP8 SDK  5.0.5.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Classes | Public Member Functions | List of all members
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...

Classes

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

Public Member Functions

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

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 has 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

template<class T, class U>
CoreOrderedHashTable< T, U >::CoreOrderedHashTable ( const unsigned int &  default_size = 16)
inlineexplicit

Default Constructor.

Parameters
specifiesdefault dictionary size
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

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
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
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
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
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
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
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
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
template<class T , class U >
CoreArray< U > CoreOrderedHashTable< T, U >::get_values ( ) const

Get all the data of the dictionary as an array.

Returns
an array of data
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
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
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()
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
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
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
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
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
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