Clarisse 5.0 SP8 SDK  5.0.5.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Classes | Public Types | Public Member Functions | List of all members
CoreHashTable< T, U > Class Template Reference

Access efficient template collection of Key/Value objects couples The CoreHashTable is meant to be used as a general purpose hash table structure. The hash table has two distinct implementation. The first one is a sparse structure when the number of items is smaller than a predefined threshold (256). The second implementation is a hash table. The sparse implementation is basically a vector on which the search is performed linearly. When the number of items is rather small, typically lower than 256, the sparse table performs faster that a dense one. The dense hash table overhead is overkill for a small amount of items. The implementation is automatically switched in runtime, between sparse or dense, according to the actual number of items. More...

Classes

class  Iterator
 

Public Types

enum  HashImplType {
  HASH_IMPL_TYPE_NONE,
  HASH_IMPL_TYPE_SPARSE,
  HASH_IMPL_TYPE_DENSE
}
 

Public Member Functions

 CoreHashTable (const unsigned int &hash_size=0)
 
 init ()
 
 CoreHashTable (const CoreHashTable &src)
 
 copy_from (src)
 
 CoreHashTable (std::initializer_list< CorePair< T, U >> table)
 
 for (const auto &item:table)
 
void reserve (const unsigned int &nb_elements, const bool &preserve_elements=false)
 
void add (const T &key, const U &item)
 add a new key/value entry in the hash table, if key does not already exist. If key already exists, set its value.
 
U & get_value (const T &key) const
 Gets value associated to incoming key. Key entry MUST exist, use CoreHashTable::is_key_exists if you don't know.
 
void remove (const T &key)
 Removes entry from table.
 
void remove_all (const bool keep_implem=false)
 Clears table.
 
void refit ()
 Refit the table (reduces memory size and improves performance if many items are deleted)
 
const unsigned int & get_count () const
 Gets entries count.
 
CoreArray< T > get_keys () const
 Returns an array containing all hashtable keys.
 
CoreArray< U > get_values () const
 Returns an array containing all hashtable values.
 
U * is_key_exists (const T &key) const
 Checks if there is a hashtable entry associated to incoming key.
 
void copy_from (const CoreHashTable &src)
 Replace hashtable content with incoming one's.
 
CoreHashTable< T, U > & operator= (const CoreHashTable &src)
 
CoreHashTable< T, U > & operator= (std::initializer_list< CorePair< T, U >> other)
 
U & operator[] (const T &key)
 
const U & operator[] (const T &key) const
 
size_t get_memory_size () const
 
CoreHashTableIterator< T, U, true > begin (void) const
 
CoreHashTableIterator< T, U,
false > 
begin (void)
 
CoreHashTableIterator< T, U, true > end (void) const
 
CoreHashTableIterator< T, U,
false > 
end (void)
 

Detailed Description

template<class T, class U>
class CoreHashTable< T, U >

Access efficient template collection of Key/Value objects couples The CoreHashTable is meant to be used as a general purpose hash table structure. The hash table has two distinct implementation. The first one is a sparse structure when the number of items is smaller than a predefined threshold (256). The second implementation is a hash table. The sparse implementation is basically a vector on which the search is performed linearly. When the number of items is rather small, typically lower than 256, the sparse table performs faster that a dense one. The dense hash table overhead is overkill for a small amount of items. The implementation is automatically switched in runtime, between sparse or dense, according to the actual number of items.

Member Function Documentation

template<class T , class U >
CoreHashTableIterator< T, U, true > CoreHashTable< T, U >::begin ( void  ) const
inline

Get a const iterator on the first node of the table.

template<class T , class U >
CoreHashTableIterator< T, U, false > CoreHashTable< T, U >::begin ( void  )
inline

Get an iterator on the first node of the table.

template<class T , class U >
CoreHashTableIterator< T, U, true > CoreHashTable< T, U >::end ( void  ) const
inline

Get a const iterator on the node past the last one of the table.

template<class T , class U >
CoreHashTableIterator< T, U, false > CoreHashTable< T, U >::end ( void  )
inline

Get an iterator on the node past the last one of the table.

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

Checks if there is a hashtable entry associated to incoming key.

Parameters
[in]keykey to look for.
Returns
a pointer to the associated value it yes, 0 otherwise.
template<class T, class U>
CoreHashTable<T,U>& CoreHashTable< T, U >::operator= ( std::initializer_list< CorePair< T, U >>  other)
inline

Copy from an initializer list. This is needed because CoreSet doesn't have a move assignment. When move assignment will be implemented, this operator will no longer be needed (assigning from an initializer list will just call the initializer list constructor, then the move assignment)