ston_ht32_new fix
authorken <ken@mihrtec.com>
Fri, 24 Feb 2017 18:54:11 +0000 (10:54 -0800)
committerken <ken@mihrtec.com>
Fri, 24 Feb 2017 18:54:11 +0000 (10:54 -0800)
ston/ston_ht.h

index 0864aa7..ef7a363 100644 (file)
@@ -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++)