OPIC
Object Persistence In C
op_hash_table.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 
81 OPHashTable* HTNew(OPHeap* heap, uint64_t num_objects,
82  double load, size_t keysize, size_t valsize);
83 
90 void HTDestroy(OPHashTable* table);
91 
111 bool HTInsertCustom(OPHashTable* table, OPHash hasher, void* key, void* val);
112 
149 bool HTUpsertCustom(OPHashTable* table, OPHash hasher,
150  void* key, void** val_ref, bool* is_duplicate);
151 
166 void* HTGetCustom(OPHashTable* table, OPHash hasher, void* key);
167 
179 void* HTDeleteCustom(OPHashTable* table, OPHash hasher, void* key);
180 
199 static inline bool
200 HTInsert(OPHashTable* table, void* key, void* val)
201 {
202  return HTInsertCustom(table, OPDefaultHash, key, val);
203 }
204 
240 static inline bool
241 HTUpsert(OPHashTable* table, void* key, void** val_ref, bool* is_duplicate)
242 {
243  return HTUpsertCustom(table, OPDefaultHash, key, val_ref, is_duplicate);
244 }
245 
259 static inline void*
260 HTGet(OPHashTable* table, void* key)
261 {
262  return HTGetCustom(table, OPDefaultHash, key);
263 }
264 
276 static inline void*
277 HTDelete(OPHashTable* table, void* key)
278 {
279  return HTDeleteCustom(table, OPDefaultHash, key);
280 }
281 
286 uint64_t HTObjcnt(OPHashTable* table);
287 
292 uint64_t HTCapacity(OPHashTable* table);
293 
298 size_t HTKeySize(OPHashTable* table);
299 
304 size_t HTValSize(OPHashTable* table);
305 
336 void HTIterate(OPHashTable* table, OPHashIterator iterator, void* context);
337 
344 void HTPrintStat(OPHashTable* table);
345 
346 uint32_t HTMaxProbe(OPHashTable* table);
347 
348 uint32_t HTProbeStat(OPHashTable* table, uint32_t idx);
349 
350 int HTGetProbeCustom(OPHashTable* table, OPHash hasher, void* key);
351 
352 static inline
353 int HTGetProbe(OPHashTable* table, void* key)
354 {
355  return HTGetProbeCustom(table, OPDefaultHash, key);
356 }
357 
358 HTFunnel* HTFunnelNewCustom(OPHashTable* table,
359  OPHash hasher,
360  FunnelCB callback,
361  size_t slotsize,
362  size_t partition_size);
363 
364 static inline
365 HTFunnel* HTFunnelNew(OPHashTable* table,
366  FunnelCB callback,
367  size_t slotsize,
368  size_t partition_size)
369 {
370  return HTFunnelNewCustom(table, OPDefaultHash, callback,
371  slotsize, partition_size);
372 }
373 
374 void HTFunnelDestroy(HTFunnel* funnel);
375 
376 void HTFunnelPreHashInsert(HTFunnel* funnel,
377  uint64_t hashed_key,
378  void* key, void* value);
379 
380 void HTFunnelInsert(HTFunnel* funnel, void* key, void* value);
381 
382 void HTFunnelInsertFlush(HTFunnel* funnel);
383 
384 void HTFunnelPreHashUpsert(HTFunnel* funnel,
385  uint64_t hashed_key,
386  void* key, void* value,
387  void* context, size_t ctxsize);
388 
389 void HTFunnelUpsert(HTFunnel* funnel,
390  void* key, void* value,
391  void* context, size_t ctxsize);
392 
393 void HTFunnelUpsertFlush(HTFunnel* funnel);
394 
395 void HTFunnelPreHashGet(HTFunnel* funnel, uint64_t hashed_key,
396  void* key, void* context, size_t ctxsize);
397 
398 void HTFunnelGet(HTFunnel* funnel, void* key, void* context, size_t ctxsize);
399 
400 void HTFunnelGetFlush(HTFunnel* funnel);
401 
402 void HTFunnelPreHashDelete(HTFunnel* funnel, uint64_t hashed_key,
403  void* key, void* context, size_t ctxsize);
404 
405 void HTFunnelDelete(HTFunnel* funnel, void* key,
406  void* context, size_t ctxsize);
407 
408 void HTFunnelDeleteFlush(HTFunnel* funnel);
409 
410 OP_END_DECLS
411 
412 #endif
413 
414 /* op_hash_table.h ends here */
An opaque object for doing massive update or quries on OPHashTable.
Memory allocator object with persistent storage on disk.
An opaque object that manage associations of fixed length key-value pairs.
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...
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.
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. ...
size_t HTValSize(OPHashTable *table)
Obtain the size of the value configured for this hash table.
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.
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.
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.
OPHashTable * HTNew(OPHeap *heap, uint64_t num_objects, double load, size_t keysize, size_t valsize)
Constructor for OPHashTable.
size_t HTKeySize(OPHashTable *table)
Obtain the size of the key configured for 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.
uint64_t(* OPHash)(void *key, size_t size)
Hash function interface.
Definition: op_hash.h:45