store_htable.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. typedef struct ht_store_t LSUP_HTStore;
  24. typedef struct ht_iterator_t LSUP_HTIterator;
  25. LSUP_HTStore *
  26. LSUP_htstore_new (void);
  27. /** @brief Boolean operation on hash table triples.
  28. *
  29. * The resulting store is compacted to the minimum size necessary to hold all
  30. * results.
  31. *
  32. * @param[in] op Operation type. See #LSUP_bool_op
  33. *
  34. * @param[in] s1 First store.
  35. *
  36. * @param[in] s2 Second store.
  37. *
  38. * @return New store resulting from the operation. It must be freed with
  39. * #LSUP_htstore_free after use.
  40. */
  41. LSUP_HTStore *
  42. LSUP_htstore_bool_op (
  43. const LSUP_bool_op op, const LSUP_HTStore *s1, const LSUP_HTStore *s2);
  44. /** @brief Free a hash table store.
  45. */
  46. void
  47. LSUP_htstore_free (LSUP_HTStore *ht);
  48. /** @brief Copy contents of a store to another store.
  49. *
  50. * The destination is not initialized, so copy is cumulative with the existing
  51. * content.
  52. *
  53. * @param[in] Store to copy to. It must be already initialized via
  54. * #LSUP_htstore_new(), #LSUP_HTstore_copy(), etc.
  55. *
  56. * @param[in] src Store to copy from.
  57. */
  58. LSUP_rc
  59. LSUP_htstore_copy_contents (LSUP_HTStore *dest, const LSUP_HTStore *src);
  60. LSUP_HTIterator *
  61. LSUP_htstore_add_init (LSUP_HTStore *store);
  62. /** @brief Add triples to the store.
  63. *
  64. * @param[in] store Store handle.
  65. *
  66. * @param[in] sspo Triples to add, serialized into buffer triples.
  67. */
  68. LSUP_rc
  69. LSUP_htstore_add_iter (LSUP_HTIterator *it, const LSUP_SerTriple *sspo);
  70. void
  71. LSUP_htstore_add_done (LSUP_HTIterator *it);
  72. LSUP_rc
  73. LSUP_htstore_remove(
  74. LSUP_HTStore *store, const LSUP_SerTriple *sspo, size_t *ct);
  75. LSUP_HTIterator *
  76. LSUP_htstore_lookup(
  77. LSUP_HTStore *store, const LSUP_SerTriple *sspo);
  78. size_t
  79. LSUP_htstore_size (LSUP_HTStore *ht);
  80. void
  81. LSUP_htiter_free (LSUP_HTIterator *it);
  82. size_t
  83. LSUP_htiter_cur (LSUP_HTIterator *it);
  84. LSUP_rc
  85. LSUP_htiter_next (LSUP_HTIterator *it, LSUP_SerTriple *sspo);
  86. #endif // _LSUP_STORE_HTABLE_H