diff options
author | David Robillard <d@drobilla.net> | 2018-10-28 14:00:47 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2021-03-08 23:23:05 -0500 |
commit | 800f2d0d4960061a1739a36d8b608a13896b321e (patch) | |
tree | f885ae3e85efad463f06b62a8ee48cfb23d3ff5e /include/serd/serd.h | |
parent | f0c30e3fff0072746252eb9a37334e740975f389 (diff) | |
download | serd-800f2d0d4960061a1739a36d8b608a13896b321e.tar.gz serd-800f2d0d4960061a1739a36d8b608a13896b321e.tar.bz2 serd-800f2d0d4960061a1739a36d8b608a13896b321e.zip |
Add SerdNodes class for storing a cache of nodes
Diffstat (limited to 'include/serd/serd.h')
-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 @{ */ |