26 HashData(
const std::string& _key,
const MY_TYPE& _val) :
62 template<
class MY_TYPE>
class Hash {
64 std::vector<HashData<MY_TYPE>* > m_data;
85 for (
auto &it : m_data) {
98 int64_t
getId(
const std::string& _key)
const {
99 for (
size_t iii=0; iii<m_data.size(); iii++) {
100 if (m_data[iii] !=
nullptr) {
102 if (m_data[iii]->
m_key == _key) {
115 bool exist(
const std::string& _name)
const {
116 int64_t elementId = getId(_name);
130 MY_TYPE&
get(
const std::string& _key)
const {
131 static MY_TYPE g_error;
132 int64_t elementId = getId(_key);
137 return m_data[elementId]->m_value;
144 MY_TYPE& operator[] (
const std::string& _key) {
152 const MY_TYPE& operator[] (
const std::string& _key)
const {
161 void add(
const std::string& _key,
const MY_TYPE& _value) {
162 int64_t elementId = getId(_key);
165 if (tmp ==
nullptr) {
169 m_data.push_back(tmp);
172 m_data[elementId]->m_value = _value;
180 void set(
const std::string& _key,
const MY_TYPE& _value) {
187 void remove(
const std::string& _key) {
188 int64_t elementId = getId(_key);
193 delete(m_data[elementId]);
194 m_data[elementId] =
nullptr;
195 m_data.erase(m_data.begin()+elementId);
202 return m_data.size();
210 MY_TYPE& operator[] (
size_t _pos) {
211 return getValue(_pos);
219 const MY_TYPE& operator[] (
size_t _pos)
const {
220 return getValue(_pos);
227 const std::string&
getKey(
size_t _pos)
const {
230 if(_pos>m_data.size()){
234 return m_data[_pos]->m_key;
241 std::vector<std::string> keys;
242 for (
auto &it : m_data) {
244 keys.push_back(it->m_key);
257 if(_pos>m_data.size()){
261 return m_data[_pos]->m_value;
269 if(_pos>m_data.size()){
273 return m_data[_pos]->m_value;
Hash(int32_t _count=0)
Contructor of the Hach table.
Definition: Hash.hpp:70
int32_t size() const
Get the number of element in the hash table.
Definition: Hash.hpp:201
void clear()
Remove all entry in the Hash table.
Definition: Hash.hpp:84
std::string m_key
name of the current hash
Definition: Hash.hpp:19
basic namespace of the etk library. (it might contain all the etk fuctions/class/structures without m...
Definition: Archive.hpp:16
MY_TYPE m_value
data of the current Hash
Definition: Hash.hpp:20
bool exist(const std::string &_name) const
Check if an element exist or not.
Definition: Hash.hpp:115
int64_t getId(const std::string &_key) const
Get a current element ID in the Hash table.
Definition: Hash.hpp:98
void clear()
Clear all the matrix.
Definition: Matrix.hpp:520
MY_TYPE & getValue(size_t _pos)
Get a value of the hash table at a specific position. (size_t)
Definition: Hash.hpp:266
void add(const std::string &_key, const MY_TYPE &_value)
Add an element OR set an element value.
Definition: Hash.hpp:161
HashData(const std::string &_key, const MY_TYPE &_val)
Constructor of the data for hash table.
Definition: Hash.hpp:26
~Hash()
Destructor of the Hash table(clear all element in the table)
Definition: Hash.hpp:77
std::vector< std::string > getKeys() const
Get all the element name (keys).
Definition: Hash.hpp:240
Hash table tamplate is a simple classical hash interface. A hash table is a equivalent of the diction...
Definition: Hash.hpp:62
internel data of the [class[etk::hash]] class, it contain the name and the value of the hash vector...
Definition: Hash.hpp:17
const MY_TYPE & getValue(size_t _pos) const
Get a value of the hash table at a specific position.
Definition: Hash.hpp:254
const std::string & getKey(size_t _pos) const
Get the name of the element at a specific position.
Definition: Hash.hpp:227