diff options
Diffstat (limited to 'include/serd')
-rw-r--r-- | include/serd/serd.h | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/include/serd/serd.h b/include/serd/serd.h index 09017175..7c1ff057 100644 --- a/include/serd/serd.h +++ b/include/serd/serd.h @@ -84,6 +84,9 @@ extern "C" { /// Global library state typedef struct SerdWorldImpl SerdWorld; +/// Hashing node container for interning and simplified memory management +typedef struct SerdNodesImpl SerdNodes; + /// A subject, predicate, and object, with optional graph context typedef struct SerdStatementImpl SerdStatement; @@ -1339,6 +1342,63 @@ serd_writer_finish(SerdWriter* SERD_NONNULL writer); /** @} + @defgroup serd_nodes Nodes + @{ +*/ + +/// Create a new node set +SERD_API +SerdNodes* SERD_ALLOCATED +serd_nodes_new(void); + +/** + Free `nodes` and all nodes that are stored in it. + + Note that this invalidates any pointers previously returned from + `serd_nodes_intern()` or `serd_nodes_manage()` calls on `nodes`. +*/ +SERD_API +void +serd_nodes_free(SerdNodes* SERD_NULLABLE nodes); + +/** + Intern `node`. + + Multiple calls with equivalent nodes will return the same pointer. + + @return A node that is different than, but equivalent to, `node`. +*/ +SERD_API +const SerdNode* SERD_ALLOCATED +serd_nodes_intern(SerdNodes* SERD_NONNULL nodes, + const SerdNode* SERD_NULLABLE node); + +/** + Manage `node`. + + Like `serd_nodes_intern`, but takes ownership of `node`, freeing it and + returning a previously interned/managed equivalent node if necessary. + + @return A node that is equivalent to `node`. +*/ +SERD_API +const SerdNode* SERD_ALLOCATED +serd_nodes_manage(SerdNodes* SERD_NONNULL nodes, SerdNode* SERD_NULLABLE node); + +/** + Dereference `node`. + + Decrements the reference count of `node`, and frees the internally stored + equivalent node if this was the last reference. Does nothing if no node + equivalent to `node` is stored in `nodes`. +*/ +SERD_API +void +serd_nodes_deref(SerdNodes* SERD_NONNULL nodes, + const SerdNode* SERD_NONNULL node); + +/** + @} @defgroup serd_statement Statement @{ */ |