From a5f7e9fc952612850ed7e2edbc9c262f465022d8 Mon Sep 17 00:00:00 2001 From: Tristan Brice Velloza Kildaire Date: Sat, 27 Apr 2024 16:42:07 +0200 Subject: [PATCH] VisitationTree - Documented --- source/niknaks/containers.d | 44 ++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/source/niknaks/containers.d b/source/niknaks/containers.d index 5f11708..3519fc0 100644 --- a/source/niknaks/containers.d +++ b/source/niknaks/containers.d @@ -897,22 +897,51 @@ public class VisitationTree(T) : Tree!(T) { private bool visisted; + /** + * Constructs a new node + * + * Params: + * value = the value + */ this(T value) { super(value); } + /** + * Performs the linearization + * + * Returns: the linearized list + */ public T[] linearize() { return dfs(toDelegate(&_shouldVisit), toDelegate(&_touch)); } + /** + * The inclusion startergy + * + * Params: + * tnode = the tree node + * Returns: `true` if not + * yet visited or incompatible + * node type + */ private static bool _shouldVisit(Tree!(T) tnode) { VisitationTree!(T) vnode = cast(VisitationTree!(T))tnode; return vnode && !vnode.isVisited(); } + /** + * The touching stratergy + * + * Only works on compatible + * tree nodes + * + * Params: + * tnode = the tree node + */ private static void _touch(Tree!(T) tnode) { VisitationTree!(T) vnode = cast(VisitationTree!(T))tnode; @@ -922,17 +951,31 @@ public class VisitationTree(T) : Tree!(T) } } + /** + * Marks this node as + * visited + */ private void mark() { this.visisted = true; } + /** + * Checks this node has been + * visited + * + * Returns: `true` if visited, + * otherwise `false` + */ private bool isVisited() { return this.visisted; } } +/** + * Tests out using the visitation tree + */ unittest { VisitationTree!(string) root = new VisitationTree!(string)("root"); @@ -946,5 +989,4 @@ unittest assert(linearized[0] == "subtree"); assert(linearized[1] == "root"); - } \ No newline at end of file