11typedef struct idx_entry_t {
17typedef struct ht_store_t {
22typedef struct ht_iterator_t {
37static bool lookup_none_eq_fn (
48static bool lookup_sk_eq_fn (
50{
return spok[0] == luk[0]; }
55static bool lookup_pk_eq_fn (
57{
return spok[1] == luk[1]; }
62static bool lookup_ok_eq_fn (
64{
return spok[2] == luk[2]; }
69static bool lookup_spk_eq_fn (
71{
return spok[0] == luk[0] && spok[1] == luk[1]; }
76static bool lookup_sok_eq_fn (
78{
return spok[0] == luk[0] && spok[2] == luk[2]; }
83static bool lookup_pok_eq_fn (
85{
return spok[1] == luk[1] && spok[2] == luk[2]; }
90static bool lookup_spok_eq_fn (
92{
return spok[0] == luk[0] && spok[1] == luk[1] && spok[2] == luk[2]; }
98 const void *item, uint64_t seed0, uint64_t seed1)
117static uint64_t htstore_idx_hash_fn (
118 const void *item, uint64_t seed0, uint64_t seed1)
130static int htstore_idx_cmp_fn (
const void *a,
const void *b,
void *udata)
141static void htstore_idx_free_fn (
void *item)
179htstore_new (
const char *
id,
size_t size)
186 ht->
idx = hashmap_new (
188 htstore_idx_hash_fn, htstore_idx_cmp_fn, htstore_idx_free_fn,
191 ht->
keys = hashmap_new (
207 while (hashmap_iter (src->
keys, &i, (
void **) &spok)) {
208 hashmap_set (dest->
keys, spok);
212 while (hashmap_iter (src->
idx, &i, (
void **) &entry)) {
213 hashmap_set (dest->
idx, entry);
223htstore_free (
void *h)
226 hashmap_free (store->
idx);
227 hashmap_free (store->
keys);
233htstore_size (
const void *h)
236 return hashmap_count (store->
keys);
241htstore_add_term (
void *h,
const VOLK_Buffer *sterm,
void *_unused)
250 entry_s.
data = malloc (sterm->
size);
255 hashmap_set (store->
idx, &entry_s);
263htstore_add_init (
void *h,
const VOLK_Buffer *_unused,
void *_unused2)
286 VOLK_rc rc = add_key_iter (it, spok);
290 for (
int i = 0; i < 3; i++)
298htstore_add_done (
void *h)
309 const VOLK_Buffer *_unused,
void *_unused2,
size_t *ct)
322 if (hashmap_count (store->
keys) == 0)
return it;
329 if (ss && sp && so) {
330 it->
eq_fn = lookup_spok_eq_fn;
335 it->
eq_fn = lookup_spk_eq_fn;
339 it->
eq_fn = lookup_sok_eq_fn;
343 it->
eq_fn = lookup_sk_eq_fn;
349 it->
eq_fn = lookup_pok_eq_fn;
352 }
else it->
eq_fn = lookup_pk_eq_fn;
356 it->
eq_fn = lookup_ok_eq_fn;
359 }
else it->
eq_fn = lookup_none_eq_fn;
365 while (htiter_next_key (it) ==
VOLK_OK) (*ct)++;
380 void *_unused2,
size_t *ct_p)
387 HTIterator *it = htstore_lookup (store, ss, sp, so, NULL, NULL, &ct);
396 while (htiter_next_key (it) ==
VOLK_OK) {
398 "Deleting {%lx, %lx, %lx}.",
407 if (ct_p) *ct_p = ct;
427 "Found spok: {%lx, %lx, %lx}",
447 VOLK_rc rc = htiter_next_key (it);
450 return tkey_to_strp (it->
store, *it->
entry, sspo);
455 .name =
"Hashtable Store",
459 .new_fn = htstore_new,
460 .free_fn = htstore_free,
462 .size_fn = htstore_size,
464 .add_init_fn = htstore_add_init,
465 .add_iter_fn = htstore_add_iter,
466 .add_done_fn = htstore_add_done,
467 .add_term_fn = htstore_add_term,
469 .lookup_fn = htstore_lookup,
470 .lu_next_fn = htiter_next,
473 .remove_fn = htstore_remove,
488 for (
int i = 0; i < 3; i++) {
489 tmp = hashmap_get (store->
idx, spok + i);
504 LOG_TRACE(
"Inserting spok: {%lx, %lx, %lx}", spok[0], spok[1], spok[2]);
506 if (hashmap_get (it->
store->
keys, spok)) {
511 LOG_TRACE(
"Triple not found, inserting.");
513 hashmap_set (it->
store->
keys, (
void *)spok);
VOLK_Key VOLK_buffer_hash(const VOLK_Buffer *buf)
Hash a buffer.
VOLK_Buffer * VOLK_btriple_pos(const VOLK_BufferTriple *trp, VOLK_TriplePos n)
Get serialized triple by term position.
#define VOLK_HASH_SEED
Seed used for all hashing. Compile-time configurable.
#define VOLK_HASH(...)
Default hashing function. Depends on architecture.
#define MALLOC_GUARD(var, rc)
Allocate one pointer with malloc and return rc if it fails.
#define CALLOC_GUARD(var, rc)
Allocate one pointer with calloc and return rc if it fails.
size_t VOLK_Key
Term key, i.e., hash of a serialized term.
VOLK_Key VOLK_TripleKey[3]
Array of three VOLK_Key values, representing a triple.
#define VOLK_VALUE_ERR
An invalid input value was provided.
#define VOLK_MEM_ERR
Memory allocation error.
#define VOLK_NORESULT
No result yielded.
#define VOLK_DB_ERR
Low-level database error.
#define VOLK_END
Loop end.
#define VOLK_OK
Generic success return code.
#define VOLK_NOACTION
No action taken.
@ VOLK_STORE_COW
Copy on write.
bool(* VOLK_key_eq_fn_t)(const VOLK_Key spok[], const VOLK_Key luk[])
const VOLK_StoreInt htstore_int
int trp_key_cmp_fn(const void *a, const void *b, void *udata)
uint64_t trp_key_hash_fn(const void *item, uint64_t seed0, uint64_t seed1)
Simple in-memory triple store back end based on hash tables.
VOLK_TripleKey * entry
Retrieved SPO key.
VOLK_key_eq_fn_t eq_fn
Equality function to test triples.
size_t cur
Internal hash table cursor.
VOLK_Key luk[3]
0รท3 lookup keys.
HTStore * store
Store being iterated.
struct hashmap * keys
Triple keys (set).
struct hashmap * idx
Map of keys to serialized terms.
VOLK_Key key
Serialized term key.
size_t size
Serialized term size.
void * data
Serialized term data.
General-purpose data buffer.