From 1d5095cf6789fc26c7eface8b68d747d85dbf02e Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Thu, 18 Jul 2019 17:44:47 +0000 Subject: plugin/file: Rename do to walk and cleanup and document (#2987) * plugin/file: Rename do to walk, cleanup and document * This renames Do to Walk to be more inline with Go standards. Also make it return an error instead of a bool. Also give give walk access to rrs. Alternatively e.m could be exported, but just access the map of rrs should work as well. Another alternative would be adding a whole bunch of helper functions, but those need grab and return the data. Just having access to the rrs should be easiest for most Walks. * It adds Type and TypeForWildcard to show the different functions * *Removes* the identical RR check when inserting; this was only done for A, AAAA and MX and not finished; removed under the mantra garbage in garbage out. * Reuses Types to return all the types in an *tree.Elem Signed-off-by: Miek Gieben * better comments Signed-off-by: Miek Gieben --- plugin/file/tree/all.go | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) (limited to 'plugin/file/tree/all.go') diff --git a/plugin/file/tree/all.go b/plugin/file/tree/all.go index fd806365f..e1fc5b392 100644 --- a/plugin/file/tree/all.go +++ b/plugin/file/tree/all.go @@ -1,6 +1,6 @@ package tree -// All traverses tree and returns all elements +// All traverses tree and returns all elements. func (t *Tree) All() []*Elem { if t.Root == nil { return nil @@ -19,30 +19,3 @@ 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 -} -- cgit v1.2.3