From f2b80599da1fdc080340ac391e8fa6d077221a16 Mon Sep 17 00:00:00 2001 From: Stephan Soller Date: Wed, 12 Jul 2017 21:39:23 +0200 Subject: [PATCH] Released slim_hash 1.1. --- README.md | 9 +++++---- slim_hash.h | 32 ++------------------------------ 2 files changed, 7 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 2b07101..bdcada3 100644 --- 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 diff --git a/slim_hash.h b/slim_hash.h index 32c918f..eea6e53 100644 --- a/slim_hash.h +++ b/slim_hash.h @@ -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 -- 2.20.1