graph.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #ifndef _LSUP_GRAPH_H
  2. #define _LSUP_GRAPH_H
  3. #include "keyset.h"
  4. #include "index.h"
  5. #include "triple.h"
  6. typedef enum LSUP_store_type {
  7. LSUP_STORE_MEM,
  8. LSUP_STORE_MDB
  9. } LSUP_store_type;
  10. typedef struct LSUP_Graph {
  11. LSUP_store_type store_type;
  12. LSUP_Keyset *keys;
  13. LSUP_Term *uri;
  14. LSUP_Index *idx;
  15. } LSUP_Graph;
  16. typedef void (*lookup_callback_fn_t)(
  17. LSUP_Graph gr, const LSUP_TripleKey* spok_p, void* ctx
  18. );
  19. int
  20. LSUP_graph_init(
  21. LSUP_Graph *gr, size_t capacity, char *uri_str,
  22. LSUP_store_type store_type);
  23. LSUP_Graph *
  24. LSUP_graph_new(size_t capacity, char *uri_str, LSUP_store_type store_type);
  25. bool
  26. LSUP_graph_contains(const LSUP_Graph *gr, const LSUP_Triple *t);
  27. /**
  28. * Add triples to a graph.
  29. */
  30. int
  31. LSUP_graph_add(LSUP_Graph *gr, LSUP_Triple data[], size_t data_size);
  32. /**
  33. * Set-theoretical union (gr1 ∪ gr2).
  34. *
  35. * The resulting Keyset is initialized beforehand and is not compacted.
  36. */
  37. int LSUP_graph_join(LSUP_Graph *gr1, LSUP_Graph *gr2, LSUP_Graph *res);
  38. /**
  39. * Set-theoretical complement (gr1 \ gr2).
  40. *
  41. * The resulting Keyset is initialized beforehand and is not compacted.
  42. */
  43. int LSUP_graph_subtract(LSUP_Graph *gr1, LSUP_Graph *gr2, LSUP_Graph *res);
  44. /**
  45. * Set-theoretical intersection (gr1 ∩ gr2).
  46. *
  47. * The resulting Keyset is initialized beforehand and is not compacted.
  48. */
  49. int LSUP_graph_intersect(LSUP_Graph *gr1, LSUP_Graph *gr2, LSUP_Graph *res);
  50. /**
  51. * Disjunctive union (XOR) (gr1 ⊕ gr2).
  52. *
  53. * The resulting Keyset is initialized beforehand and is not compacted.
  54. */
  55. int LSUP_graph_xor(LSUP_Graph *gr1, LSUP_Graph *gr2, LSUP_Graph *res);
  56. void
  57. LSUP_graph_free(LSUP_Graph *gr);
  58. /** Extern inline functions. */
  59. inline size_t
  60. LSUP_graph_capacity(LSUP_Graph *gr) { return gr->keys->capacity; }
  61. inline size_t
  62. LSUP_graph_size(LSUP_Graph *gr) { return gr->keys->free_i; }
  63. #endif