store_htable.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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_HTStore *
  27. LSUP_htstore_new(size_t capacity);
  28. /** @brief Boolean operation on hash table triples.
  29. *
  30. * The resulting store is compacted to the minimum size necessary to hold all
  31. * results.
  32. *
  33. * @param op[in] Operation type. See #LSUP_bool_op
  34. *
  35. * @param s1[in] First store.
  36. *
  37. * @param s2[in] Second store.
  38. *
  39. * @return New store resulting from the operation. It must be freed with
  40. * #LSUP_htstore_free after use.
  41. */
  42. LSUP_HTStore *
  43. LSUP_htstore_bool_op(
  44. const LSUP_bool_op op, const LSUP_HTStore *s1, const LSUP_HTStore *s2);
  45. void
  46. LSUP_htstore_free(LSUP_HTStore *ht);
  47. LSUP_rc
  48. LSUP_htstore_resize(LSUP_HTStore *ht, htsize_t size);
  49. LSUP_rc
  50. LSUP_htstore_add(LSUP_HTStore *store, const LSUP_SerTriple *sspo);
  51. LSUP_rc
  52. LSUP_htstore_remove(
  53. LSUP_HTStore *store, const LSUP_SerTriple *sspo, size_t *ct);
  54. LSUP_HTIterator *
  55. LSUP_htstore_lookup(
  56. LSUP_HTStore *store, const LSUP_SerTriple *sspo, size_t *ct);
  57. htsize_t
  58. LSUP_htstore_size(LSUP_HTStore *ht);
  59. htsize_t
  60. LSUP_htstore_capacity(const LSUP_HTStore *ht);
  61. LSUP_rc
  62. LSUP_htiter_next(LSUP_HTIterator *it, LSUP_SerTriple *sspo);
  63. void
  64. LSUP_htiter_free(LSUP_HTIterator *it);
  65. #endif // _LSUP_STORE_HTABLE_H