summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Beckett <dave@dajobe.org>2020-09-05 16:48:23 -0700
committerGitHub <noreply@github.com>2020-09-05 16:48:23 -0700
commita21dc80a381735c83062f797a18f94b760d3156f (patch)
tree11067a4f8cfc785894ca5e4b24e107943cfe8806
parent91ae65be6f1c822739a70098350c50abd86f30ad (diff)
parente1fd1160715478ca9b59073f52ea76f674a67bdb (diff)
downloadraptor-a21dc80a381735c83062f797a18f94b760d3156f.tar.gz
Merge pull request #38 from hroptatyr/feat/turtle-flush
provide raptor_turtle_serialize_flush()
-rw-r--r--src/raptor2.h.in2
-rw-r--r--src/raptor_avltree.c17
-rw-r--r--src/raptor_serialize_turtle.c27
3 files changed, 46 insertions, 0 deletions
diff --git a/src/raptor2.h.in b/src/raptor2.h.in
index 6c7707a5..f9b9f94a 100644
--- a/src/raptor2.h.in
+++ b/src/raptor2.h.in
@@ -2153,6 +2153,8 @@ void* raptor_avltree_remove(raptor_avltree* tree, void* p_data);
RAPTOR_API
int raptor_avltree_delete(raptor_avltree* tree, void* p_data);
RAPTOR_API
+void raptor_avltree_trim(raptor_avltree* tree);
+RAPTOR_API
void* raptor_avltree_search(raptor_avltree* tree, const void* p_data);
RAPTOR_API
int raptor_avltree_visit(raptor_avltree* tree, raptor_avltree_visit_handler visit_handler, void* user_data);
diff --git a/src/raptor_avltree.c b/src/raptor_avltree.c
index 32311071..5059eaaf 100644
--- a/src/raptor_avltree.c
+++ b/src/raptor_avltree.c
@@ -329,6 +329,23 @@ raptor_avltree_delete(raptor_avltree* tree, void* p_data)
}
+/**
+ * raptor_avltree_trim:
+ * @tree: AVLTree object
+ *
+ * Delete all nodes from an AVL tree but keep the shell.
+ */
+void
+raptor_avltree_trim(raptor_avltree* tree)
+{
+ if(!tree)
+ return;
+
+ raptor_free_avltree_internal(tree, tree->root);
+ tree->root = NULL;
+}
+
+
static int
raptor_avltree_visit_internal(raptor_avltree* tree, raptor_avltree_node* node,
int depth,
diff --git a/src/raptor_serialize_turtle.c b/src/raptor_serialize_turtle.c
index aa3930ad..3ba5e60f 100644
--- a/src/raptor_serialize_turtle.c
+++ b/src/raptor_serialize_turtle.c
@@ -145,6 +145,7 @@ static int raptor_turtle_serialize_statement(raptor_serializer* serializer,
raptor_statement *statement);
static int raptor_turtle_serialize_end(raptor_serializer* serializer);
+static int raptor_turtle_serialize_flush(raptor_serializer* serializer);
static void raptor_turtle_serialize_finish_factory(raptor_serializer_factory* factory);
@@ -1471,6 +1472,31 @@ raptor_turtle_serialize_end(raptor_serializer* serializer)
return 0;
}
+/* flush turtle */
+static int
+raptor_turtle_serialize_flush(raptor_serializer* serializer)
+{
+ raptor_turtle_context* context = (raptor_turtle_context*)serializer->context;
+
+ raptor_turtle_ensure_writen_header(serializer, context);
+
+ raptor_turtle_emit(serializer);
+
+ if(context->subjects) {
+ raptor_avltree_trim(context->subjects);
+ }
+
+ if(context->blanks) {
+ raptor_avltree_trim(context->blanks);
+ }
+
+ if(context->nodes) {
+ raptor_avltree_trim(context->nodes);
+ }
+
+ return 0;
+}
+
/* finish the serializer factory */
static void
@@ -1528,6 +1554,7 @@ raptor_turtle_serializer_register_factory(raptor_serializer_factory *factory)
factory->serialize_start = raptor_turtle_serialize_start;
factory->serialize_statement = raptor_turtle_serialize_statement;
factory->serialize_end = raptor_turtle_serialize_end;
+ factory->serialize_flush = raptor_turtle_serialize_flush;
factory->finish_factory = raptor_turtle_serialize_finish_factory;
return 0;