aboutsummaryrefslogtreecommitdiff
path: root/middleware/file/tree/all.go
diff options
context:
space:
mode:
Diffstat (limited to 'middleware/file/tree/all.go')
-rw-r--r--middleware/file/tree/all.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/middleware/file/tree/all.go b/middleware/file/tree/all.go
new file mode 100644
index 000000000..f621e3465
--- /dev/null
+++ b/middleware/file/tree/all.go
@@ -0,0 +1,21 @@
+package tree
+
+// All traverses tree and returns all elements
+func (t *Tree) All() []*Elem {
+ if t.Root == nil {
+ return nil
+ }
+ found := t.Root.all(nil)
+ return found
+}
+
+func (n *Node) all(found []*Elem) []*Elem {
+ if n.Left != nil {
+ found = n.Left.all(found)
+ }
+ found = append(found, n.Elem)
+ if n.Right != nil {
+ found = n.Right.all(found)
+ }
+ return found
+}