store_htable.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 "buffer.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. /** Add a term to the index.
  61. *
  62. * @parm[in] store HTStore handle.
  63. *
  64. * @param[in] sterm Serialized term to insert.
  65. *
  66. * @return LSUP_OK on success; LSUP_NOACTION if the term exists already; <0
  67. * on error.
  68. */
  69. LSUP_rc
  70. LSUP_htstore_add_term (LSUP_HTStore *store, const LSUP_Buffer *sterm);
  71. LSUP_HTIterator *
  72. LSUP_htstore_add_init (LSUP_HTStore *store);
  73. /** @brief Add triples to the store.
  74. *
  75. * @param[in] store Store handle.
  76. *
  77. * @param[in] sspo Triples to add, serialized into buffer triples.
  78. */
  79. LSUP_rc
  80. LSUP_htstore_add_iter (LSUP_HTIterator *it, const LSUP_BufferTriple *sspo);
  81. void
  82. LSUP_htstore_add_done (LSUP_HTIterator *it);
  83. LSUP_rc
  84. LSUP_htstore_remove(
  85. LSUP_HTStore *store, const LSUP_Buffer *ss, const LSUP_Buffer *sp,
  86. const LSUP_Buffer *so, size_t *ct);
  87. LSUP_HTIterator *
  88. LSUP_htstore_lookup(
  89. LSUP_HTStore *store, const LSUP_Buffer *ss, const LSUP_Buffer *sp,
  90. const LSUP_Buffer *so);
  91. size_t
  92. LSUP_htstore_size (LSUP_HTStore *ht);
  93. void
  94. LSUP_htiter_free (LSUP_HTIterator *it);
  95. size_t
  96. LSUP_htiter_cur (LSUP_HTIterator *it);
  97. LSUP_rc
  98. LSUP_htiter_next (LSUP_HTIterator *it, LSUP_BufferTriple *sspo);
  99. #endif // _LSUP_STORE_HTABLE_H