Released slim_hash 1.1.
authorStephan Soller <stephan.soller@helionweb.de>
Wed, 12 Jul 2017 19:39:23 +0000 (21:39 +0200)
committerStephan Soller <stephan.soller@helionweb.de>
Wed, 12 Jul 2017 19:43:03 +0000 (21:43 +0200)
README.md
slim_hash.h

index 2b07101..bdcada3 100644 (file)
--- a/README.md
+++ b/README.md
@@ -6,7 +6,8 @@ extract them and clean them up.
 
 All libraries are published under the MIT license.
 
-library               | lastest version | category | description
---------------------- | --------------- | -------- | --------------------------------
-**math_3d.h**         | 1.0             | graphics | compact 3D math library for use with OpenGL
-**slim_test.h**       | 1.0             | testing  | small set of functions to build simple test programs
+library               | lastest version | category  | description
+--------------------- | --------------- | --------- | --------------------------------
+**math_3d.h**         | 1.0             | graphics  | compact 3D math library for use with OpenGL
+**slim_hash.h**       | 1.1             | container | simple and easy to use hashmap for C99
+**slim_test.h**       | 1.0             | testing   | small set of functions to build simple test programs
index 32c918f..eea6e53 100644 (file)
@@ -155,7 +155,6 @@ course have different type names and function prefixes.
     
     void  dict_new(struct dict* hashmap);
     void  dict_destroy(struct dict* hashmap);
-    void  dict_optimize(struct dict* hashmap);
     
     int   dict_get(struct dict* hashmap, char* key, int default_value);
     void  dict_put(struct dict* hashmap, char* key, int value);
@@ -176,11 +175,12 @@ See the function implementations in the SH_GEN_IMPL() macro for detailed documen
 VERSION HISTORY
 
 v1.0  2016-06-22  Initial release
-xxxx  xxxx-xx-xx  ADD: Added the fnv1a 32 bit hash function (see sh_fnv1a() documentation).
+v1.1  2017-07-12  ADD: Added the fnv1a 32 bit hash function (see sh_fnv1a() documentation).
                   ADD: Manually ported the murmur3 hash function from the original source. Also
                        added the seed parameter (again, see sh_murmur3() docs).
                   ADD: Added calloc and free expressions to SH_GEN_IMPL() so memory can be allocated
                        from a garbage collector.
+                  CHANGE: Removed the ..._optimize() function because it didn't improve performance.
                   CHANGE: Cleaned up the code and added documentation.
                   CHANGE: The hashmap now uses power to two capacities.
                   CHANGE: Made typedefs optional. They can be removed by defining
@@ -195,11 +195,6 @@ xxxx  xxxx-xx-xx  ADD: Added the fnv1a 32 bit hash function (see sh_fnv1a() docu
                        generate.
                   FIX: Added missing prototypes for functions shared by all implementations.
 
-
-TODO
-
-- remove optimize function
-
 **/
 #ifndef SLIM_HASH_HEADER
 #define SLIM_HASH_HEADER
@@ -256,7 +251,6 @@ uint32_t sh_fnv1a(const char* key);
                                                                                                    \
     void     name##_new(struct name* hashmap);                                                     \
     void     name##_destroy(struct name* hashmap);                                                 \
-    void     name##_optimize(struct name* hashmap);                                                \
                                                                                                    \
     value_t  name##_get(struct name* hashmap, key_t key, value_t default_value);                   \
     void     name##_put(struct name* hashmap, key_t key, value_t value);                           \
@@ -682,28 +676,6 @@ uint32_t sh_fnv1a(const char* key);
         }                                                                                          \
                                                                                                    \
         return false;                                                                              \
-    }                                                                                              \
-                                                                                                   \
-    /**                                                                                         */ \
-    /* Rehashes all keys in the hashmap. This is the same as inserting all key-value pairs one  */ \
-    /* after the other into a new hashmap.                                                      */ \
-    /*                                                                                          */ \
-    /* This function is only usfull if you degenerated the hashmap by _a lot_ of inserts and    */ \
-    /* deletions that caused collisions.  If you plan _a lot_ of lookups after that optimizing  */ \
-    /* the hashmap might help performance.                                                      */ \
-    void name##_optimize(struct name* hashmap) {                                                   \
-        uint32_t new_capacity = hashmap->length;                                                   \
-                                                                                                   \
-        /* http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2 */                  \
-        new_capacity--;                                                                            \
-        new_capacity |= new_capacity >> 1;                                                         \
-        new_capacity |= new_capacity >> 2;                                                         \
-        new_capacity |= new_capacity >> 4;                                                         \
-        new_capacity |= new_capacity >> 8;                                                         \
-        new_capacity |= new_capacity >> 16;                                                        \
-        new_capacity++;                                                                            \
-                                                                                                   \
-        name##_resize(hashmap, new_capacity * 2);                                                  \
     }                                                                                              \
 
 #if _SVID_SOURCE || _BSD_SOURCE || _XOPEN_SOURCE >= 500 || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED || _POSIX_C_SOURCE >= 200809L