aboutsummaryrefslogtreecommitdiffstats
path: root/serd
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-10-28 14:00:47 +0100
committerDavid Robillard <d@drobilla.net>2019-04-13 19:15:32 +0200
commit05fbb2be9950175a517fda17e0d65135b4eaeab6 (patch)
tree04a282657ca5af093fa47b83e30673e6c0c99f36 /serd
parentbc46da00532dd8896c1bddb3b1f279811b25d4a1 (diff)
downloadserd-05fbb2be9950175a517fda17e0d65135b4eaeab6.tar.gz
serd-05fbb2be9950175a517fda17e0d65135b4eaeab6.tar.bz2
serd-05fbb2be9950175a517fda17e0d65135b4eaeab6.zip
Add SerdNodes class for storing a cache of nodes
Diffstat (limited to 'serd')
-rw-r--r--serd/serd.h65
1 files changed, 65 insertions, 0 deletions
diff --git a/serd/serd.h b/serd/serd.h
index 4fc2dc63..17febad9 100644
--- a/serd/serd.h
+++ b/serd/serd.h
@@ -62,6 +62,14 @@ extern "C" {
typedef struct SerdWorldImpl SerdWorld;
/**
+ Nodes.
+
+ A hashing container for nodes that can be used for interning and simplified
+ memory management.
+*/
+typedef struct SerdNodesImpl SerdNodes;
+
+/**
Statement.
A subject, predicate, and object, with optional graph context.
@@ -1301,6 +1309,63 @@ serd_writer_finish(SerdWriter* writer);
/**
@}
+ @name Nodes
+ @{
+*/
+
+/**
+ Create a new node set.
+*/
+SERD_API
+SerdNodes*
+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* 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_nodes_intern(SerdNodes* nodes, const SerdNode* 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_nodes_manage(SerdNodes* nodes, SerdNode* 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* nodes, const SerdNode* node);
+
+/**
+ @}
@name Statement
@{
*/