- struct hashlistnode {
- _Key key;
- _Val val;
- struct hashlistnode<_Key,_Val> *next;
- };
-
-template<typename _Key, typename _Val, typename _KeyInt, int _Shift>
- class HashTable {
- public:
- HashTable(unsigned int initialcapacity=1024, double factor=0.5) {
+struct hashlistnode {
+ _Key key;
+ _Val val;
+};
+
+/**
+ * @brief A simple, custom hash table
+ *
+ * By default it is snapshotting, but you can pass in your own allocation
+ * functions. Note that this table does not support the value 0 (NULL) used as
+ * a key and is designed primarily with pointer-based keys in mind. Other
+ * primitive key types are supported only for non-zero values.
+ *
+ * @tparam _Key Type name for the key
+ * @tparam _Val Type name for the values to be stored
+ * @tparam _KeyInt Integer type that is at least as large as _Key. Used for key
+ * manipulation and storage.
+ * @tparam _Shift Logical shift to apply to all keys. Default 0.
+ * @tparam _malloc Provide your own 'malloc' for the table, or default to
+ * snapshotting.
+ * @tparam _calloc Provide your own 'calloc' for the table, or default to
+ * snapshotting.
+ * @tparam _free Provide your own 'free' for the table, or default to
+ * snapshotting.
+ */
+template<typename _Key, typename _Val, typename _KeyInt, int _Shift = 0, void * (*_malloc)(size_t) = snapshot_malloc, void * (*_calloc)(size_t, size_t) = snapshot_calloc, void (*_free)(void *) = snapshot_free>
+class HashTable {
+public:
+ /**
+ * @brief Hash table constructor
+ * @param initialcapacity Sets the initial capacity of the hash table.
+ * Default size 1024.
+ * @param factor Sets the percentage full before the hashtable is
+ * resized. Default ratio 0.5.
+ */
+ HashTable(unsigned int initialcapacity = 1024, double factor = 0.5) {