31 #define IGNORE_IN_CLASSLIST
33 #define MapNode CMapNode<K, T>
35 #ifndef DOXYGEN_SHOULD_SKIP_THIS
66 CMap(int32_t size=41, int32_t reserved=128,
bool tracable=
true)
76 hash_array=(CMapNode<K, T>**) calloc(size,
sizeof(CMapNode<K, T>*));
78 for (int32_t i=0; i<size; i++)
93 virtual const char*
get_name()
const {
return "Map"; }
101 int32_t
add(
const K& key,
const T& data)
103 int32_t index=hash(key);
104 if (chain_search(index, key)==NULL)
107 int32_t added_index=insert_key(index, key, data);
124 int32_t index=hash(key);
125 if (chain_search(index, key)!=NULL)
135 void remove(
const K& key)
137 int32_t index=hash(key);
138 CMapNode<K, T>* result=chain_search(index, key);
143 delete_key(index, result);
156 int32_t index=hash(key);
157 CMapNode<K ,T>* result=chain_search(index, key);
160 return result->index;
173 int32_t index=hash(key);
174 CMapNode<K, T>* result=chain_search(index, key);
180 int32_t added_index=
add(key, T());
194 int32_t index=hash(key);
195 CMapNode<K, T>* result=chain_search(index, key);
235 if (result!=NULL && !is_free(result))
271 sizeof(CMapNode<K, T>*));
280 for (
int i = 0; i < orig.num_elements; i++)
282 CMapNode<K, T>*
node = orig.array->get_element(i);
283 add(node->key, node->data);
293 int32_t hash(
const K& key)
299 bool is_free(CMapNode<K, T>*
node)
301 if (node->free==
true)
308 CMapNode<K, T>* chain_search(int32_t index,
const K& key)
319 if (current->key==key)
322 current=current->right;
324 }
while (current!=NULL);
331 int32_t insert_key(int32_t index,
const K& key,
const T& data)
340 new_node=SG_CALLOC(
MapNode, 1);
342 new_node=(CMapNode<K, T>*) calloc(1,
sizeof(CMapNode<K, T>));
344 new (&new_node->key) K();
345 new (&new_node->data) T();
358 free_index=new_node->index;
361 new_node->index=new_index;
362 new_node->free=false;
366 new_node->right=NULL;
385 void delete_key(int32_t index, CMapNode<K, T>* node)
392 if (node->right!=NULL)
393 node->right->left = node->left;
395 if (node->left!=NULL)
396 node->left->right = node->right;
T get_element(int32_t index) const
CMap(int32_t size=41, int32_t reserved=128, bool tracable=true)
CMapNode< K, T > ** hash_array
int32_t index_of(const K &key)
bool append_element(T element)
node< P > new_node(const P &p)
virtual const char * get_name() const
T get_element(const K &key)
CMapNode< K, T > ** get_array()
void set_element(const K &key, const T &data)
int32_t get_num_elements() const
virtual uint32_t get_hash_value(const K &key)
bool contains(const K &key)
static uint32_t MurmurHash3(uint8_t *data, int32_t len, uint32_t seed)
T * get_element_ptr(int32_t index)
CMapNode< K, T > * get_node_ptr(int32_t index)
int32_t get_array_size() const
int32_t add(const K &key, const T &data)
Class Lock used for synchronization in concurrent programs.
Template Dynamic array class that creates an array that can be used like a list or an array...
CMap & operator=(const CMap &orig)
#define IGNORE_IN_CLASSLIST
DynArray< CMapNode< K, T > * > * array
all of classes and functions are contained in the shogun namespace
int32_t get_num_elements() const
the class CMap, a map based on the hash-table. w: http://en.wikipedia.org/wiki/Hash_table ...