store_htable.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /** @file store.htable.h
  2. *
  3. * @brief Simple in-memory triple store back end based on hash tables.
  4. *
  5. * This is the simplest choice to do in-memory manipulation of RDF graphs and
  6. * it has some limitations: most notably, it only supports triples without
  7. * context (one graph per store) and it is not indexed. This means that it is
  8. * optimized for fast writes and sequential lookups (iteration). Lookups on
  9. * arbitrary terms are supported but require iterating over all the triples.
  10. * This implementation is most convenient for graphs where retrieval is done
  11. * via iteration.
  12. *
  13. * Also, as it may be obvious, this store is not persistent.
  14. *
  15. * For faster random lookups and persistence, the MDB backend is preferred. If
  16. * persistence is not required (e.g. ingesting and manipulating a very large
  17. * graph and outputting some results on a file) an ad-hoc MDB store located in
  18. * RAM disk can be used, which is much faster.
  19. */
  20. #ifndef _LSUP_STORE_HTABLE_H
  21. #define _LSUP_STORE_HTABLE_H
  22. #include "triple.h"
  23. #include "htable.h"
  24. typedef struct HTStore LSUP_HTStore;
  25. typedef struct HTIterator LSUP_HTIterator;
  26. LSUP_rc
  27. LSUP_htstore_new(size_t capacity, LSUP_HTStore **ht_p);
  28. void
  29. LSUP_htstore_free(LSUP_HTStore *ht);
  30. LSUP_rc
  31. LSUP_htstore_resize(LSUP_HTStore *ht, htsize_t size);
  32. LSUP_rc
  33. LSUP_htstore_add(LSUP_HTStore *store, const LSUP_SerTriple *sspo);
  34. LSUP_rc
  35. LSUP_htstore_remove(
  36. LSUP_HTStore *store, const LSUP_SerTriple *sspo, size_t *ct);
  37. LSUP_rc
  38. LSUP_htstore_lookup(
  39. LSUP_HTStore *store, const LSUP_SerTriple *sspo,
  40. LSUP_HTIterator **it_p, size_t *ct);
  41. htsize_t
  42. LSUP_htstore_size(LSUP_HTStore *ht);
  43. htsize_t
  44. LSUP_htstore_capacity(const LSUP_HTStore *ht);
  45. LSUP_rc
  46. LSUP_htiter_next(LSUP_HTIterator *it, LSUP_SerTriple *sspo);
  47. void
  48. LSUP_htiter_free(LSUP_HTIterator *it);
  49. /** @brief Boolean operation on hash table triples.
  50. *
  51. * The resulting store is compacted to the minimum size necessary to hold all
  52. * results.
  53. *
  54. * @param op[in] Operation type. See #LSUP_bool_op
  55. *
  56. * @param s1[in] First store.
  57. *
  58. * @param s2[in] Second store.
  59. *
  60. * @param dest[out] Destination store. It must be freed with #LSUP_htstore_free
  61. * after use.
  62. */
  63. LSUP_rc
  64. LSUP_htstore_bool_op(
  65. const LSUP_bool_op op, const LSUP_HTStore *s1, const LSUP_HTStore *s2,
  66. LSUP_HTStore **dest);
  67. #endif // _LSUP_STORE_HTABLE_H