OPIC
Object Persistence In C
pascal_hash_table.h
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
12  * published by the Free Software Foundation, either version 3 of the
13  * License, or (at 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
21  * License along with this program. If not, see
22  * <http://www.gnu.org/licenses/>.
23  */
24 
25 /* Code: */
26 
27 #ifndef OPIC_HASH_PASCAL_ROBIN_HOOD_HASH
28 #define OPIC_HASH_PASCAL_ROBIN_HOOD_HASH 1
29 
30 #include <stdbool.h>
31 #include "opic/common/op_macros.h"
32 #include "opic/op_malloc.h"
33 #include "op_hash.h"
34 
35 OP_BEGIN_DECLS
36 
44 typedef struct PascalHashTable PascalHashTable;
45 
61 PascalHashTable* PHNew(OPHeap* heap, uint64_t num_objects, double load,
62  size_t key_inline_size, size_t valsize);
63 
73 void PHDestroy(PascalHashTable* rhh);
74 
95 bool PHInsertCustom(PascalHashTable* rhh, OPHash hasher,
96  void* key, size_t keysize, void* val);
97 
118 bool PHUpsertCustom(PascalHashTable* rhh, OPHash hasher,
119  void* key, size_t keysize, void** val_ref,
120  bool* is_duplicate);
121 
137 void* PHGetCustom(PascalHashTable* rhh, OPHash hasher,
138  void* key, size_t keysize);
139 
153 void* PHDeleteCustom(PascalHashTable* rhh, OPHash hasher,
154  void* key, size_t keysize);
155 
176 static inline bool
177 PHInsert(PascalHashTable* rhh, void* key, size_t keysize, void* val)
178 {
179  return PHInsertCustom(rhh, OPDefaultHash, key, keysize, val);
180 }
181 
201 static inline bool
202 PHUpsert(PascalHashTable* rhh, void* key, size_t keysize,
203  void** val_ref, bool* is_duplicate)
204 {
205  return PHUpsertCustom(rhh, OPDefaultHash, key, keysize,
206  val_ref, is_duplicate);
207 }
208 
223 static inline void*
224 PHGet(PascalHashTable* rhh, void* key, size_t keysize)
225 {
226  return PHGetCustom(rhh, OPDefaultHash, key, keysize);
227 }
228 
241 static inline void*
242 PHDelete(PascalHashTable* rhh, void* key, size_t keysize)
243 {
244  return PHDeleteCustom(rhh, OPDefaultHash, key, keysize);
245 }
246 
251 uint64_t PHObjcnt(PascalHashTable* rhh);
252 
257 uint64_t PHCapacity(PascalHashTable* rhh);
258 
265 size_t PHKeyInlineSize(PascalHashTable* rhh);
266 
271 size_t PHValSize(PascalHashTable* rhh);
272 
303 void PHIterate(PascalHashTable* rhh,
304  OPHashIterator iterator, void* context);
305 
310 void PHPrintStat(PascalHashTable* rhh);
311 
312 uint32_t PHMaxProbe(PascalHashTable* rhh);
313 
314 uint32_t PHProbeStat(PascalHashTable* rhh, uint32_t idx);
315 
316 OP_END_DECLS
317 
318 #endif
319 /* pascal_robin_hood.h ends here */
Memory allocator object with persistent storage on disk.
void PHPrintStat(PascalHashTable *rhh)
Prints the accumulated count for each probing number.
static void * PHDelete(PascalHashTable *rhh, void *key, size_t keysize)
Deletes the key-value entry using default hash function.
void * PHGetCustom(PascalHashTable *rhh, OPHash hasher, void *key, size_t keysize)
Obtain the value associated with the key and hash function. Returns NULL if the key was not found...
uint64_t PHCapacity(PascalHashTable *rhh)
Obtain the number of objects can be stored in this hash table.
PascalHashTable * PHNew(OPHeap *heap, uint64_t num_objects, double load, size_t key_inline_size, size_t valsize)
Constructor for PascalHashTable.
void PHDestroy(PascalHashTable *rhh)
Destructor for PascalHashTable.
size_t PHValSize(PascalHashTable *rhh)
Obtain the size of the value configured for this hash table.
An opaque object that manages associations of key-value pairs.
void * PHDeleteCustom(PascalHashTable *rhh, OPHash hasher, void *key, size_t keysize)
Deletes the key-value entry with specified hash function.
uint64_t PHObjcnt(PascalHashTable *rhh)
Obtain the number of objects stored in this hash table.
bool PHInsertCustom(PascalHashTable *rhh, OPHash hasher, void *key, size_t keysize, void *val)
Associates the specified key and value with custom hash function.
static uint64_t OPDefaultHash(void *key, size_t size)
Default hash function.
Definition: op_hash.h:70
bool PHUpsertCustom(PascalHashTable *rhh, OPHash hasher, void *key, size_t keysize, void **val_ref, bool *is_duplicate)
Update or insert depends on whether the key already exists in the hash table using custom hash functi...
void PHIterate(PascalHashTable *rhh, OPHashIterator iterator, void *context)
Iterates over all key-value pairs in this hash table with user specified context. ...
static bool PHInsert(PascalHashTable *rhh, void *key, size_t keysize, void *val)
Associates the specified key and value using default hash function.
size_t PHKeyInlineSize(PascalHashTable *rhh)
Obtain the size of the key that can be stored inline in the hash table. If the size of the key is lar...
static bool PHUpsert(PascalHashTable *rhh, void *key, size_t keysize, void **val_ref, bool *is_duplicate)
Update or insert depends on whether the key already exists in the 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 void * PHGet(PascalHashTable *rhh, void *key, size_t keysize)
Obtain the value associated with the key using default hash function. Returns NULL if the key was not...
uint64_t(* OPHash)(void *key, size_t size)
Hash function interface.
Definition: op_hash.h:45