_Key key;
_Val val;
uint hashcode;
- struct Hashlistnode<_Key, _Val> * next;
- struct Hashlistnode<_Key, _Val> * prev;
+ struct Hashlistnode<_Key, _Val> *next;
+ struct Hashlistnode<_Key, _Val> *prev;
};
template<typename _Key, int _Shift, typename _KeyInt>
* manipulation and storage.
* @tparam _Shift Logical shift to apply to all keys. Default 0.
*/
+
template<typename _Key, typename _Val, typename _KeyInt = uintptr_t, int _Shift = 0, unsigned int (*hash_function)(_Key) = defaultHashFunction<_Key, _Shift, _KeyInt>, bool (*equals)(_Key, _Key) = defaultEquals<_Key> >
class Hashtable {
public:
tail = list = NULL;
}
+ Hashtable<_Key, _Val, _KeyInt, _Shift, hash_function, equals> *clone() {
+ Hashtable<_Key, _Val, _KeyInt, _Shift, hash_function, equals> *ctable = new Hashtable<_Key, _Val, _KeyInt, _Shift, hash_function, equals> (capacity, loadfactor);
+ struct Hashlistnode<_Key, _Val> *ptr = list;
+ while (ptr != NULL) {
+ ctable->put(ptr->key, ptr->val);
+ ptr = ptr->next;
+ }
+ return ctable;
+ }
+
+
/** @brief Hash table destructor */
~Hashtable() {
ourfree(table);
return (_Val)0;
} else {
_Val v = zero->val;
- if (zero -> next != NULL)
- zero -> next -> prev = zero ->prev;
+ if (zero->next != NULL)
+ zero->next->prev = zero->prev;
else
- tail = zero -> prev;
+ tail = zero->prev;
- if (zero -> prev != NULL)
- zero -> prev -> next = zero -> next;
+ if (zero->prev != NULL)
+ zero->prev->next = zero->next;
else
list = zero->next;
-
+
ourfree(zero);
zero = NULL;
Size--;
//empty out this bin
search->val = (_Val) 1;
search->key = 0;
-
- if (search -> next != NULL)
- search -> next -> prev = search ->prev;
+
+ if (search->next != NULL)
+ search->next->prev = search->prev;
else
- tail = search -> prev;
-
- if (search -> prev != NULL)
- search -> prev -> next = search -> next;
+ tail = search->prev;
+
+ if (search->prev != NULL)
+ search->prev->next = search->next;
else
list = search->next;
-
+
Size--;
return v;
}
if (tail == NULL)
tail = search;
- search -> next = list;
+ search->next = list;
if (list != NULL)
- list -> prev = search;
+ list->prev = search;
list = search;
search->hashcode = hashcode;
search->key = key;
unsigned int getCapacity() {return capacity;}
struct Hashlistnode<_Key, _Val> *table;
struct Hashlistnode<_Key, _Val> *zero;
- struct Hashlistnode<_Key, _Val> * list;
- struct Hashlistnode<_Key, _Val> * tail;
- unsigned int capacity;
+ struct Hashlistnode<_Key, _Val> *list;
+ struct Hashlistnode<_Key, _Val> *tail;
+ unsigned int capacity;
unsigned int Size;
private:
unsigned int capacitymask;