123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- #ifndef _LSUP_GRAPH_H
- #define _LSUP_GRAPH_H
- #include "triple.h"
- typedef enum LSUP_store_type {
- LSUP_STORE_MEM,
- LSUP_STORE_MDB
- } LSUP_store_type;
- typedef struct Graph LSUP_Graph;
- /**
- * Post-lookup callback type.
- *
- * src is the graph that yielded a match. Its index ponts at the matched triple
- * key and is accessible via `keyset_peek(ks)`.
- *
- * dest is an optional keyset that may be acted upon. It may be NULL.
- *
- * ctx is an optional arbitrary pointer to additional data that may be used
- * by the callback.
- */
- typedef int (*keyset_match_fn_t)(LSUP_Graph *src, LSUP_Graph *dest, void *ctx);
- int
- LSUP_graph_init(
- LSUP_Graph *gr, size_t capacity, char *uri_str,
- LSUP_store_type store_type);
- LSUP_Graph *
- LSUP_graph_new(size_t capacity, char *uri_str, LSUP_store_type store_type);
- int
- LSUP_graph_copy(LSUP_Graph *src, LSUP_Graph *dest);
- size_t
- LSUP_graph_capacity(LSUP_Graph *gr);
- size_t
- LSUP_graph_size(LSUP_Graph *gr);
- char *
- LSUP_graph_uri(LSUP_Graph *gr);
- bool
- LSUP_graph_contains(const LSUP_Graph *gr, const LSUP_Triple *t);
- /**
- * Execute a custom function on a graph based on a match pattern.
- *
- * This function executes an arbitrary callback on a graph, `res`, based on
- * triples matched by a pattern on graph `gr`. `res` must be initialized but
- * need not be empty. `res` can point to the same object as `gr` if changes
- * are to be done in place (e.g. removing triples).
- *
- * @param[in] gr Graph to perform pattern matching.
- * @param[out] res Result graph to apply the callback to.
- * @param[in] spo Triple pattern. Each term of the triple members can be either
- * a term pointer or NULL. If NULL, the term is unbound.
- * @param[in] callback_fn Callback function to apply.
- * @param[in] match_cond If true, apply the callback to each triple a match is
- * found for. Otherwise, apply to each triple no match is found for.
- * @param[in|out] ctx Arbitrary context that may be handled in the callback
- * function.
- *
- * @return LSUP_OK on match, LSUP_NOACTION on no match, <0 on error.
- */
- int LSUP_graph_match_callback(
- LSUP_Graph *gr, LSUP_Graph *res, const LSUP_Triple *spo,
- keyset_match_fn_t callback_fn, bool match_cond, void *ctx);
- /**
- * Add triples to a graph.
- */
- int
- LSUP_graph_add(LSUP_Graph *gr, const LSUP_Triple data[], size_t data_size);
- int LSUP_graph_lookup(LSUP_Graph *gr, LSUP_Graph *res, const LSUP_Triple *spo);
- /**
- * Set-theoretical union (gr1 ∪ gr2).
- *
- * The resulting Keyset is initialized beforehand and is not compacted.
- */
- int LSUP_graph_join(LSUP_Graph *gr1, LSUP_Graph *gr2, LSUP_Graph *res);
- /**
- * Set-theoretical complement (gr1 \ gr2).
- *
- * The resulting Keyset is initialized beforehand and is not compacted.
- */
- int LSUP_graph_subtract(LSUP_Graph *gr1, LSUP_Graph *gr2, LSUP_Graph *res);
- /**
- * Set-theoretical intersection (gr1 ∩ gr2).
- *
- * The resulting Keyset is initialized beforehand and is not compacted.
- */
- int LSUP_graph_intersect(LSUP_Graph *gr1, LSUP_Graph *gr2, LSUP_Graph *res);
- /**
- * Disjunctive union (XOR) (gr1 ⊕ gr2).
- *
- * The resulting Keyset is initialized beforehand and is not compacted.
- */
- int LSUP_graph_xor(LSUP_Graph *gr1, LSUP_Graph *gr2, LSUP_Graph *res);
- void
- LSUP_graph_free(LSUP_Graph *gr);
- #endif
|