OPIC
Object Persistence In C
robin_hood.h
Go to the documentation of this file.
1 
10 /* This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU Lesser General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or (at
13  * your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful, but
16  * WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 /* Code: */
25 
26 #ifndef OPIC_HASH_HASH_TABLE_H
27 #define OPIC_HASH_HASH_TABLE_H 1
28 
29 #include <stdbool.h>
30 #include "opic/common/op_macros.h"
31 #include "op_hash.h"
32 #include "opic/op_malloc.h"
33 
34 OP_BEGIN_DECLS
35 
55 typedef struct OPHashTable OPHashTable;
56 
66 typedef struct HTFunnel HTFunnel;
67 
83 bool HTNew(OPHeap* heap, OPHashTable** table_ref, uint64_t num_objects,
84  double load, size_t keysize, size_t valsize);
85 
92 void HTDestroy(OPHashTable* table);
93 
113 bool HTInsertCustom(OPHashTable* table, OPHash hasher, void* key, void* val);
114 
151 bool HTUpsertCustom(OPHashTable* table, OPHash hasher,
152  void* key, void** val_ref, bool* is_duplicate);
153 
168 void* HTGetCustom(OPHashTable* table, OPHash hasher, void* key);
169 
181 void* HTDeleteCustom(OPHashTable* table, OPHash hasher, void* key);
182 
201 static inline bool
202 HTInsert(OPHashTable* table, void* key, void* val)
203 {
204  return HTInsertCustom(table, OPDefaultHash, key, val);
205 }
206 
242 static inline bool
243 HTUpsert(OPHashTable* table, void* key, void** val_ref, bool* is_duplicate)
244 {
245  return HTUpsertCustom(table, OPDefaultHash, key, val_ref, is_duplicate);
246 }
247 
261 static inline void*
262 HTGet(OPHashTable* table, void* key)
263 {
264  return HTGetCustom(table, OPDefaultHash, key);
265 }
266 
278 static inline void*
279 HTDelete(OPHashTable* table, void* key)
280 {
281  return HTDeleteCustom(table, OPDefaultHash, key);
282 }
283 
288 uint64_t HTObjcnt(OPHashTable* table);
289 
294 uint64_t HTCapacity(OPHashTable* table);
295 
300 size_t HTKeysize(OPHashTable* table);
301 
306 size_t HTValsize(OPHashTable* table);
307 
338 void HTIterate(OPHashTable* table, OPHashIterator iterator, void* context);
339 
345 void HTPrintStat(OPHashTable* table);
346 
347 uint32_t HTMaxProbe(OPHashTable* table);
348 
349 uint32_t HTProbeStat(OPHashTable* table, uint32_t idx);
350 
351 int HTGetProbeCustom(OPHashTable* table, OPHash hasher, void* key);
352 
353 static inline
354 int HTGetProbe(OPHashTable* table, void* key)
355 {
356  return HTGetProbeCustom(table, OPDefaultHash, key);
357 }
358 
359 HTFunnel* HTFunnelNewCustom(OPHashTable* table,
360  OPHash hasher,
361  FunnelCB callback,
362  size_t slotsize,
363  size_t partition_size);
364 
365 static inline
366 HTFunnel* HTFunnelNew(OPHashTable* table,
367  FunnelCB callback,
368  size_t slotsize,
369  size_t partition_size)
370 {
371  return HTFunnelNewCustom(table, OPDefaultHash, callback,
372  slotsize, partition_size);
373 }
374 
375 void HTFunnelDestroy(HTFunnel* funnel);
376 
377 void HTFunnelPreHashInsert(HTFunnel* funnel,
378  uint64_t hashed_key,
379  void* key, void* value);
380 
381 void HTFunnelInsert(HTFunnel* funnel, void* key, void* value);
382 
383 void HTFunnelInsertFlush(HTFunnel* funnel);
384 
385 void HTFunnelPreHashUpsert(HTFunnel* funnel,
386  uint64_t hashed_key,
387  void* key, void* value,
388  void* context, size_t ctxsize);
389 
390 void HTFunnelUpsert(HTFunnel* funnel,
391  void* key, void* value,
392  void* context, size_t ctxsize);
393 
394 void HTFunnelUpsertFlush(HTFunnel* funnel);
395 
396 void HTFunnelPreHashGet(HTFunnel* funnel, uint64_t hashed_key,
397  void* key, void* context, size_t ctxsize);
398 
399 void HTFunnelGet(HTFunnel* funnel, void* key, void* context, size_t ctxsize);
400 
401 void HTFunnelGetFlush(HTFunnel* funnel);
402 
403 void HTFunnelPreHashDelete(HTFunnel* funnel, uint64_t hashed_key,
404  void* key, void* context, size_t ctxsize);
405 
406 void HTFunnelDelete(HTFunnel* funnel, void* key,
407  void* context, size_t ctxsize);
408 
409 void HTFunnelDeleteFlush(HTFunnel* funnel);
410 
411 OP_END_DECLS
412 
413 #endif
414 
415 /* hash_table.h ends here */
An opaque object for doing massive update or quries on OPHashTable.
Opaque object for memory allocation.
An opaque object that manage associations of fixed length key-value pairs.
bool HTNew(OPHeap *heap, OPHashTable **table_ref, uint64_t num_objects, double load, size_t keysize, size_t valsize)
Constructor for OPHashTable.
size_t HTValsize(OPHashTable *table)
Obtain the size of the value configured for this hash table.
bool HTUpsertCustom(OPHashTable *table, OPHash hasher, void *key, void **val_ref, bool *is_duplicate)
Update or insert depends on whether the key already exists in the hash table using custom hash functi...
static bool HTInsert(OPHashTable *table, void *key, void *val)
Associates the specified key with the specified value in OPHashTable using the default hash function...
Definition: robin_hood.h:202
void HTPrintStat(OPHashTable *table)
Prints the accumulated count for each probing number.
static void * HTDelete(OPHashTable *table, void *key)
Deletes the key-value entry in hash table using the default hash function.
Definition: robin_hood.h:279
void * HTGetCustom(OPHashTable *table, OPHash hasher, void *key)
Obtain the value associated with the specified key and hash function. Returns NULL if the key was not...
void HTIterate(OPHashTable *table, OPHashIterator iterator, void *context)
Iterates over all key-value pairs in this hash table with user specified context. ...
void * HTDeleteCustom(OPHashTable *table, OPHash hasher, void *key)
Deletes the key-value entry in hash table with specified hasher.
static void * HTGet(OPHashTable *table, void *key)
Obtain the value associated with the specified key using the default hash function. Returns NULL if the key was not found.
Definition: robin_hood.h:262
static uint64_t OPDefaultHash(void *key, size_t size)
Default hash function.
Definition: op_hash.h:70
bool HTInsertCustom(OPHashTable *table, OPHash hasher, void *key, void *val)
Associates the specified key with the specified value in OPHashTable with specified hash function...
void HTDestroy(OPHashTable *table)
Destructor for OPHashTable.
size_t HTKeysize(OPHashTable *table)
Obtain the size of the key configured for this hash table.
uint64_t HTCapacity(OPHashTable *table)
Obtain the number of objects can be stored in this hash table.
uint64_t HTObjcnt(OPHashTable *table)
Obtain the number of objects stored in this hash table.
void(* OPHashIterator)(void *key, void *value, size_t keysize, size_t valsize, void *context)
HashTable iterator interface.
Definition: op_hash.h:59
static bool HTUpsert(OPHashTable *table, void *key, void **val_ref, bool *is_duplicate)
Update or insert depends on whether the key already exists in the hash table.
Definition: robin_hood.h:243
uint64_t(* OPHash)(void *key, size_t size)
Hash function interface.
Definition: op_hash.h:45