diff options
author | 2016-04-02 16:56:16 +0100 | |
---|---|---|
committer | 2016-04-02 16:56:16 +0100 | |
commit | 9b21646954c8fea174be8b769f16ddb213286753 (patch) | |
tree | 026a7d0419640906905429459d663af4064467ad /middleware/file/tree/all.go | |
parent | d8ab95cd18144e8701b4bb9d5f2d96fc74ab1149 (diff) | |
download | coredns-9b21646954c8fea174be8b769f16ddb213286753.tar.gz coredns-9b21646954c8fea174be8b769f16ddb213286753.tar.zst coredns-9b21646954c8fea174be8b769f16ddb213286753.zip |
empty non-terminal support
When looking for a name in tree, return wether we got to a longer one -
if so we had an ent. Add tests + dnssec tests and refactor the tests as
well a bit.
Diffstat (limited to 'middleware/file/tree/all.go')
-rw-r--r-- | middleware/file/tree/all.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/middleware/file/tree/all.go b/middleware/file/tree/all.go index f621e3465..fd806365f 100644 --- a/middleware/file/tree/all.go +++ b/middleware/file/tree/all.go @@ -19,3 +19,30 @@ func (n *Node) all(found []*Elem) []*Elem { } return found } + +// Do performs fn on all values stored in the tree. A boolean is returned indicating whether the +// Do traversal was interrupted by an Operation returning true. If fn alters stored values' sort +// relationships, future tree operation behaviors are undefined. +func (t *Tree) Do(fn func(e *Elem) bool) bool { + if t.Root == nil { + return false + } + return t.Root.do(fn) +} + +func (n *Node) do(fn func(e *Elem) bool) (done bool) { + if n.Left != nil { + done = n.Left.do(fn) + if done { + return + } + } + done = fn(n.Elem) + if done { + return + } + if n.Right != nil { + done = n.Right.do(fn) + } + return +} |