etk::Hash< MY_TYPE > Class Template Reference

#include <Hash.hpp>

Public Member Functions

 Hash (int32_t _count=0)
 
 ~Hash ()
 
void clear ()
 
int64_t getId (const std::string &_key) const
 
bool exist (const std::string &_name) const
 
MY_TYPE & get (const std::string &_key) const
 
MY_TYPE & operator[] (const std::string &_key)
 
const MY_TYPE & operator[] (const std::string &_key) const
 
void add (const std::string &_key, const MY_TYPE &_value)
 
void set (const std::string &_key, const MY_TYPE &_value)
 
void remove (const std::string &_key)
 
int32_t size () const
 
MY_TYPE & operator[] (size_t _pos)
 
const MY_TYPE & operator[] (size_t _pos) const
 
const std::string & getKey (size_t _pos) const
 
std::vector< std::string > getKeys () const
 
const MY_TYPE & getValue (size_t _pos) const
 
MY_TYPE & getValue (size_t _pos)
 

Detailed Description

template<class MY_TYPE>
class etk::Hash< MY_TYPE >

Hash table tamplate is a simple classical hash interface. A hash table is a equivalent of the dictionary in python, this is a simple interfaace between a name and a value:

  • "name" : 19
  • "name 2" : 99
Note
The name is unique and the value is what you want
Todo:
check if something ele exist in the STD. (not the std::map and the std::unordered_map
Note
The index are all time availlable since they are created. The order is the the one created

A simple example of use:

// Create a integer hash table
Hash<int> myValue;
// add some element (note add and set is the same function)
myValue.add("example", 98837);
myValue.add("plop", 88);
// Display an element:
printf("my value is : %d", myValue["example"]);
// Change value of an element:
myValue.set("example", 99);
// Remove an element:
myValue.remove("plop");
//Clean all the table:
myValue.clear();

Constructor & Destructor Documentation

§ Hash()

template<class MY_TYPE >
etk::Hash< MY_TYPE >::Hash ( int32_t  _count = 0)
inline

Contructor of the Hach table.

Parameters
[in]_countNumber ob basic elent in the vector.

§ ~Hash()

template<class MY_TYPE >
etk::Hash< MY_TYPE >::~Hash ( )
inline

Destructor of the Hash table(clear all element in the table)

Member Function Documentation

§ add()

template<class MY_TYPE >
void etk::Hash< MY_TYPE >::add ( const std::string &  _key,
const MY_TYPE &  _value 
)
inline

Add an element OR set an element value.

Note
add and set is the same function.
Parameters
[in]_keyName of the value to set in the hash table.
[in]_valueValue to set in the hash table.

§ clear()

template<class MY_TYPE >
void etk::Hash< MY_TYPE >::clear ( )
inline

Remove all entry in the Hash table.

Note
It does not delete pointer if your value is a pointer type...

§ exist()

template<class MY_TYPE >
bool etk::Hash< MY_TYPE >::exist ( const std::string &  _name) const
inline

Check if an element exist or not.

Parameters
[in]_nameName of the hash requested
Returns
true if the element exist

§ get()

template<class MY_TYPE >
MY_TYPE& etk::Hash< MY_TYPE >::get ( const std::string &  _key) const
inline

Get a current element in the hash table, with his name.

Parameters
[in]_keyName of the hash requested
Returns
Reference on the Element

§ getId()

template<class MY_TYPE >
int64_t etk::Hash< MY_TYPE >::getId ( const std::string &  _key) const
inline

Get a current element ID in the Hash table.

Parameters
[in]_keyName of the hash requested
Returns
Id of the element in the table or -1 of it does not existed

§ getKey()

template<class MY_TYPE >
const std::string& etk::Hash< MY_TYPE >::getKey ( size_t  _pos) const
inline

Get the name of the element at a specific position.

Parameters
[in]_posPosition of the element in the hash table.
Returns
name of the element (key).

§ getKeys()

template<class MY_TYPE >
std::vector<std::string> etk::Hash< MY_TYPE >::getKeys ( ) const
inline

Get all the element name (keys).

Returns
a vector of all name (key).

§ getValue() [1/2]

template<class MY_TYPE >
const MY_TYPE& etk::Hash< MY_TYPE >::getValue ( size_t  _pos) const
inline

Get a value of the hash table at a specific position.

Parameters
[in]_posof the element in the hash table.
Returns
Value availlable at this position.

§ getValue() [2/2]

template<class MY_TYPE >
MY_TYPE& etk::Hash< MY_TYPE >::getValue ( size_t  _pos)
inline

Get a value of the hash table at a specific position. (size_t)

Parameters
[in]_posof the element in the hash table.
Returns
Value availlable at this position. (size_t)

§ operator[]() [1/4]

template<class MY_TYPE >
MY_TYPE& etk::Hash< MY_TYPE >::operator[] ( const std::string &  _key)
inline

Get an copy Element an a special position.

Parameters
[in]_keyName of the hash requested
Returns
An reference on the copy of selected element

§ operator[]() [2/4]

template<class MY_TYPE >
const MY_TYPE& etk::Hash< MY_TYPE >::operator[] ( const std::string &  _key) const
inline

Get an copy Element an a special position.

Parameters
[in]_keyName of the hash requested
Returns
An reference on the copy of selected element

§ operator[]() [3/4]

template<class MY_TYPE >
MY_TYPE& etk::Hash< MY_TYPE >::operator[] ( size_t  _pos)
inline

get an element with his id.

Parameters
[in]_posPosition on the element in the hash table.
Returns
requested element at this position.
Note
this is a dangerous use of the hash table. Maybe you will use a simple vector.

§ operator[]() [4/4]

template<class MY_TYPE >
const MY_TYPE& etk::Hash< MY_TYPE >::operator[] ( size_t  _pos) const
inline

get an element with his id.

Parameters
[in]_posPosition on the element in the hash table.
Returns
requested element at this position.
Note
this is a dangerous use of the hash table. Maybe you will use a simple vector.

§ remove()

template<class MY_TYPE >
void etk::Hash< MY_TYPE >::remove ( const std::string &  _key)
inline

Remove an element in the hash table.

Parameters
[in]_keyName of the element to remove.

§ set()

template<class MY_TYPE >
void etk::Hash< MY_TYPE >::set ( const std::string &  _key,
const MY_TYPE &  _value 
)
inline

Set an element value.

Note
add and set is the same function.
Parameters
[in]_keyName of the value to set in the hash table.
[in]_valueValue to set in the hash table.

§ size()

template<class MY_TYPE >
int32_t etk::Hash< MY_TYPE >::size ( ) const
inline

Get the number of element in the hash table.

Returns
number of elements

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