From 07879707fd9e57470869013ef17e86fd91cc83e9 Mon Sep 17 00:00:00 2001 From: ken Date: Fri, 24 Feb 2017 10:54:11 -0800 Subject: [PATCH] ston_ht32_new fix --- ston/ston_ht.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/ston/ston_ht.h b/ston/ston_ht.h index 0864aa7..ef7a363 100644 --- a/ston/ston_ht.h +++ b/ston/ston_ht.h @@ -71,7 +71,7 @@ uint32_t* ston_ht32_row(ston_ht,uint32_t); STON_FUNC uint32_t ston_ht32_insert(ston_ht,uint32_t,uint16_t,uint32_t); -#define ston_ht32_new(_COL,_N,_FN) ston_ht32_create(_COLS,ston_up2pow(_N << 1),0,_FN) +#define ston_ht32_new(_COL,_N,_F,_FN) ston_ht32_create(_COLS,ston_up2pow(_N << 1),_F,_FN) #define ston_ht32_col(_HT,_KEY,_COL) (ston_ht32_row(_HT,_KEY) + _COL) #define ston_ht32_insertx(_HT,_KEY,_COL,_VAL) *ston_ht32_col(_HT,_KEY,_COL) = _VAL #define ston_ht_size(_HT) ((_HT)->ht_columns << (_HT)->ht_2pow) @@ -96,10 +96,13 @@ size_t ston_up2pow } /* Creates a new hash table, provided a memory allocation function that takes a - single size_t bytes, a column count, and a row count which estimates the - number of unique keys held in the table. The provided ht_rows is doubled, - and rounded up to the nearest power of two to create a hash table with - minimal collisions. + single size_t bytes, a column count, and a row count which determines the + size of the table. + + use ston_ht32_new to specify the exact or estimated number of unique keys + held in the table. With ston_ht32_new, the provided ht_rows is doubled, and + rounded up to the nearest power of two to create a hash table with minimal + collisions. */ STON_FUNC ston_ht ston_ht32_create @@ -108,7 +111,7 @@ ston_ht ston_ht32_create uint8_t ht_flags, void* (*alloc_fn)(size_t) ) -{ size_t ht_size = ston_up2pow(ht_rows << 1) * ht_columns * sizeof(uint32_t); +{ size_t ht_size = ht_rows * ht_columns * sizeof(uint32_t); ston_ht ht = (ston_ht) alloc_fn(sizeof(struct ston_ht_header_t) + ht_size); if (ht != NULL) { for (ht->ht_2pow = 0; ht_size; ht->ht_2pow++) -- 2.18.0