class: etk::Hash


Description:

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:
Note:
The name is unique and the value is what you want.

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 and Destructor:

+                                 Hash         (int32_t _count);
+ ~Hash (void );

Synopsis:

+ void                            clear        (void );
+ 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 (void ) const;
+ MY_TYPE & operator [ ] (size_t _pos);
+ const MY_TYPE & operator [ ] (size_t _pos) const;
+ const std::string & getKey (size_t _pos) const;
+ const MY_TYPE & getValue (size_t _pos) const;
+ MY_TYPE & getValue (size_t _pos);

Detail:

Hash

+  Hash (int32_t _count);
Contructor of the Hach table.


~Hash

+  ~Hash (void );
Destructor of the Hash table(clear all element in the table)


clear

+ void clear (void );
Remove all entry in the Hash table.
Note: It does not delete pointer if your value is a pointer type...


getId

+ int64_t getId (const std::string & _key) const;
Get a current element ID in the Hash table


exist

+ bool exist (const std::string & _name) const;
Check if an element exist or not


get

+ MY_TYPE & get (const std::string & _key) const;
Get a current element in the hash table, with his name.


operator [ ]

+ MY_TYPE & operator [ ] (const std::string & _key);
+ const MY_TYPE & operator [ ] (const std::string & _key) const;
Get an copy Element an a special position


add

+ void add (const std::string & _key,
const MY_TYPE & _value);
+ void set (const std::string & _key,
const MY_TYPE & _value);
Add an element OR set an element value
Note: add and set is the same function.


remove

+ void remove (const std::string & _key);
Remove an element in the hash table.


size

+ int32_t size (void ) const;
Get the number of element in the hash table


operator [ ]

+ MY_TYPE & operator [ ] (size_t _pos);
+ const MY_TYPE & operator [ ] (size_t _pos) const;
get an element with his id.
Note: this is a dangerous use of the hash table. Maybe you will use a simple vector.


getKey

+ const std::string & getKey (size_t _pos) const;
Get the name of the element at a specific position.


getValue

+ const MY_TYPE & getValue (size_t _pos) const;
+ MY_TYPE & getValue (size_t _pos);
Get a value of the hash table at a specific position.