123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- #ifndef _LSUP_GRAPH_H
- #define _LSUP_GRAPH_H
- #include "store_mdb.h"
- /*
- * Define backend types and checks.
- */
- #define BACKEND_TBL \
- ENTRY( MEM, 0)/* Memory backend, hash map. */ \
- ENTRY( MDB, 1)/* LMDB back end on persistent disk. */ \
- ENTRY( MDB_TMP, 2)/* LMDB back end on RAM disk. */ \
- typedef enum LSUP_store_type {
- #define ENTRY(a, b) LSUP_STORE_##a = b,
- BACKEND_TBL
- #undef ENTRY
- } LSUP_store_type;
- /** @brief Graph object.
- */
- typedef struct Graph LSUP_Graph;
- /** @brief Graph iterator.
- *
- * This opaque handle is generated by #LSUP_graph_lookup and is used to iterate
- * over lookup results with #LSUP_graph_iter_next. It must be freed with
- * #LSUP_graph_iter_free when done.
- */
- typedef struct GraphIterator LSUP_GraphIterator;
- /** @brief Create an empty graph.
- *
- * The new graph has zero capacity and a random URN. To change either one, use
- * #LSUP_graph_resize and #LSUP_graph_set_uri, respectively.
- *
- * @param store_type[in] TYpe of store for the graph. One of the values of
- * #LSUP_store_type.
- *
- * @param gr[out] Pointer to a pointer to the new graph. It must be freed with
- * #LSUP_graph_free when done.
- *
- * @return LSUP_OK if the graph was created, or < 0 if an error occurred.
- */
- LSUP_Graph *
- LSUP_graph_new (const LSUP_store_type store_type);
- /** @brief copy a graph into a new one.
- *
- * The new graph is compacted to the minimum required size.
- *
- * src[in] Graph to be copied.
- *
- * @param uri URI of the destination graph. If NULL, a UUID4 URN is generated.
- *
- * @param gr[out] Pointer to a pointer to the destination graph. It must be
- * freed with #LSUP_graph_free when done.
- *
- * @return LSUP_OK if the graph was copied, or < 0 if an error occurred.
- */
- LSUP_Graph *
- LSUP_graph_copy (const LSUP_Graph *src);
- /** Perform a boolean operation between two graphs.
- *
- * This method yields a new graph as the result of the operation.
- *
- * @param op[in] Operation to perform. One of #LSUP_bool_op.
- *
- * @param gr1[in] First operand.
- *
- * @param gr2[in] Second operand.
- *
- * @param res[out] Result graph. It must be freed with #LSUP_graph_free when
- * done.
- */
- LSUP_Graph *
- LSUP_graph_bool_op(
- const LSUP_bool_op op, const LSUP_Graph *gr1, const LSUP_Graph *gr2);
- /** @brief Free a graph.
- */
- void
- LSUP_graph_free (LSUP_Graph *gr);
- /** @brief Number of triples that can be stored without resizing the graph.
- *
- * @return Dynamic capacity of an in-memory graph or maximum allowed memory for
- * an MDB graph.
- */
- size_t
- LSUP_graph_capacity (const LSUP_Graph *gr);
- /** @brief Number of triples in a graph.
- */
- size_t
- LSUP_graph_size (const LSUP_Graph *gr);
- /** @brief Change the capacity of an in-memory graph.
- *
- * This is useful ahead of a bulk load to save multiple reallocs. Otherwise,
- * the graph expands automatically on new inserts when capacity is reached.
- *
- * @param gr[in] Graph to be resized.
- *
- * @param size[in] New size. This will never be smaller than the current
- * occupied space. Therefore setting this value to 0 effectively compacts the
- * graph storage.
- *
- * @return LSUP_OK if the operation was successful; LSUP_VALUE_ERR if the store
- * type of the graph is not LSUP_STORE_MEM; <0 if an error occurs while
- * resizing.
- */
- LSUP_rc
- LSUP_graph_resize (LSUP_Graph *gr, size_t size);
- /** @brief Read-only graph URI.
- *
- * To change the graph URI, use #LSUP_graph_set_uri.
- */
- LSUP_Term *
- LSUP_graph_uri (const LSUP_Graph *gr);
- /** Set the URI of a graph.
- *
- * @param gr[in] Graph whose URI is to be changed.
- *
- * @param uri[in] New URI as a string. If NULL, a UUID4 URN is generated.
- */
- LSUP_rc
- LSUP_graph_set_uri (LSUP_Graph *gr, const char *uri);
- bool
- LSUP_graph_contains (const LSUP_Graph *gr, const LSUP_Triple *spo);
- LSUP_GraphIterator *
- LSUP_graph_add_stream_init (LSUP_Graph *gr);
- LSUP_rc
- LSUP_graph_add_stream_iter (
- LSUP_GraphIterator *it, const LSUP_SerTriple *sspo);
- void
- LSUP_graph_add_stream_done (LSUP_GraphIterator *it);
- /** @brief Add triples and/or serialized triples to a graph.
- *
- * For API users it may be more convenient to use the more specialized
- * #LSUP_graph_add_trp.
- */
- LSUP_rc
- LSUP_graph_add(
- LSUP_Graph *gr,
- const LSUP_Triple trp[], size_t trp_ct,
- const LSUP_SerTriple strp[], size_t strp_ct, size_t *inserted);
- #define LSUP_graph_add_trp(gr, trp, ct, ins) \
- LSUP_graph_add (gr, trp, ct, NULL, 0, ins)
- /** @brief Delete triples by a matching pattern.
- *
- * @param gr[in] Graph to delete triples from.
- *
- * @param ptn[in] Matching pattern. Any and all of s, p, o can be NULL.
- *
- * @param ct[out] If not NULL it is populated with the number of triples
- * deleted.
- */
- LSUP_rc
- LSUP_graph_remove (LSUP_Graph *gr, const LSUP_Triple *spo, size_t *ct);
- /** Look up triples by a matching pattern and yield an iterator.
- *
- * @param gr[in] Graph to look up.
- *
- * @param spo[in] Triple to look for. Any and all terms can be NULL, which
- * indicate unbound terms.
- *
- * @param it[out] Pointer to a #LSUP_GraphIterator to be generated. It must be
- * freed with #LSUP_graph_iter_free after use.
- */
- LSUP_GraphIterator *
- LSUP_graph_lookup (const LSUP_Graph *gr, const LSUP_Triple *spo, size_t *ct);
- /** @brief Advance a cursor obtained by a lookup and return a matching triple.
- *
- * @param it[in] Iterator handle obtained through #LSUP_graph_lookup.
- *
- * @param spo[out] Triple to be populated with the next result. May be NULL
- * (e.g. for counters).
- *
- * @return LSUP_OK if a result was found; LSUP_END if the end of the match list
- * was reached.
- */
- LSUP_rc
- LSUP_graph_iter_next (LSUP_GraphIterator *it, LSUP_Triple *spo);
- /** @brief Free a graph iterator.
- */
- void
- LSUP_graph_iter_free (LSUP_GraphIterator *it);
- /** @brief Get the iterator counter.
- */
- size_t
- LSUP_graph_iter_cur (LSUP_GraphIterator *it);
- #endif
|