aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2020-06-19 08:58:48 -0700
committerChris Lu <chris.lu@gmail.com>2020-06-19 09:45:42 -0700
commit55b6efb7557c3a5427e5af84e0439a82bc3b4e37 (patch)
tree0f23835dd52c3d862f19dfa503859663ad65b766
parent0e7c1a300bdbedd470dd7d80276231a86ef97e27 (diff)
downloadseaweedfs-55b6efb7557c3a5427e5af84e0439a82bc3b4e37.tar.xz
seaweedfs-55b6efb7557c3a5427e5af84e0439a82bc3b4e37.zip
fix checking visited nodes
-rw-r--r--weed/util/bounded_tree/bounded_tree.go14
-rw-r--r--weed/util/bounded_tree/bounded_tree_test.go12
2 files changed, 16 insertions, 10 deletions
diff --git a/weed/util/bounded_tree/bounded_tree.go b/weed/util/bounded_tree/bounded_tree.go
index 5aa31ef74..efe2ff93a 100644
--- a/weed/util/bounded_tree/bounded_tree.go
+++ b/weed/util/bounded_tree/bounded_tree.go
@@ -1,6 +1,8 @@
package bounded_tree
import (
+ "fmt"
+
"github.com/chrislusf/seaweedfs/weed/glog"
"github.com/chrislusf/seaweedfs/weed/util"
)
@@ -133,7 +135,7 @@ func (t *BoundedTree) HasVisited(p util.FullPath) bool {
}
components := p.Split()
- // fmt.Printf("components %v %d\n", components, len(components))
+ fmt.Printf("components %v %d\n", components, len(components))
return t.hasVisited(t.root, util.FullPath("/"), components, 0)
}
@@ -147,15 +149,15 @@ func (t *BoundedTree) hasVisited(n *Node, currentPath util.FullPath, components
return false
}
- // fmt.Printf(" hasVisited child %v %v\n", currentPath, components[i])
+ fmt.Printf(" hasVisited child %v %+v %d\n", currentPath, components, i)
- toVisitNode, found := n.Children[components[i]]
- if !found {
+ if i >= len(components) {
return true
}
- if i+1 >= len(components) {
- return false
+ toVisitNode, found := n.Children[components[i]]
+ if !found {
+ return true
}
return t.hasVisited(toVisitNode, currentPath.Child(components[i]), components, i+1)
diff --git a/weed/util/bounded_tree/bounded_tree_test.go b/weed/util/bounded_tree/bounded_tree_test.go
index 18bc2f6d5..331cc46c0 100644
--- a/weed/util/bounded_tree/bounded_tree_test.go
+++ b/weed/util/bounded_tree/bounded_tree_test.go
@@ -4,6 +4,8 @@ import (
"fmt"
"testing"
+ "github.com/stretchr/testify/assert"
+
"github.com/chrislusf/seaweedfs/weed/util"
)
@@ -59,6 +61,8 @@ func TestBoundedTree(t *testing.T) {
tree.EnsureVisited(util.FullPath("/a/b/c"), visitFn)
+ assert.Equal(t, true, tree.HasVisited(util.FullPath("/a/b")))
+
printMap(tree.root.Children)
a := tree.root.getChild("a")
@@ -110,9 +114,9 @@ func TestEmptyBoundedTree(t *testing.T) {
printMap(tree.root.Children)
- println(tree.HasVisited(util.FullPath("/a/b")))
- println(tree.HasVisited(util.FullPath("/a")))
- println(tree.HasVisited(util.FullPath("/g")))
- println(tree.HasVisited(util.FullPath("/g/x")))
+ assert.Equal(t, true, tree.HasVisited(util.FullPath("/a/b")))
+ assert.Equal(t, true, tree.HasVisited(util.FullPath("/a")))
+ assert.Equal(t, false, tree.HasVisited(util.FullPath("/g")))
+ assert.Equal(t, false, tree.HasVisited(util.FullPath("/g/x")))
}