mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
fix checking visited nodes
This commit is contained in:
parent
0e7c1a300b
commit
55b6efb755
|
@ -1,6 +1,8 @@
|
||||||
package bounded_tree
|
package bounded_tree
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/chrislusf/seaweedfs/weed/glog"
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
||||||
"github.com/chrislusf/seaweedfs/weed/util"
|
"github.com/chrislusf/seaweedfs/weed/util"
|
||||||
)
|
)
|
||||||
|
@ -133,7 +135,7 @@ func (t *BoundedTree) HasVisited(p util.FullPath) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
components := p.Split()
|
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)
|
return t.hasVisited(t.root, util.FullPath("/"), components, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,17 +149,17 @@ func (t *BoundedTree) hasVisited(n *Node, currentPath util.FullPath, components
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// fmt.Printf(" hasVisited child %v %v\n", currentPath, components[i])
|
fmt.Printf(" hasVisited child %v %+v %d\n", currentPath, components, i)
|
||||||
|
|
||||||
|
if i >= len(components) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
toVisitNode, found := n.Children[components[i]]
|
toVisitNode, found := n.Children[components[i]]
|
||||||
if !found {
|
if !found {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
if i+1 >= len(components) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return t.hasVisited(toVisitNode, currentPath.Child(components[i]), components, i+1)
|
return t.hasVisited(toVisitNode, currentPath.Child(components[i]), components, i+1)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,8 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
"github.com/chrislusf/seaweedfs/weed/util"
|
"github.com/chrislusf/seaweedfs/weed/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -59,6 +61,8 @@ func TestBoundedTree(t *testing.T) {
|
||||||
|
|
||||||
tree.EnsureVisited(util.FullPath("/a/b/c"), visitFn)
|
tree.EnsureVisited(util.FullPath("/a/b/c"), visitFn)
|
||||||
|
|
||||||
|
assert.Equal(t, true, tree.HasVisited(util.FullPath("/a/b")))
|
||||||
|
|
||||||
printMap(tree.root.Children)
|
printMap(tree.root.Children)
|
||||||
|
|
||||||
a := tree.root.getChild("a")
|
a := tree.root.getChild("a")
|
||||||
|
@ -110,9 +114,9 @@ func TestEmptyBoundedTree(t *testing.T) {
|
||||||
|
|
||||||
printMap(tree.root.Children)
|
printMap(tree.root.Children)
|
||||||
|
|
||||||
println(tree.HasVisited(util.FullPath("/a/b")))
|
assert.Equal(t, true, tree.HasVisited(util.FullPath("/a/b")))
|
||||||
println(tree.HasVisited(util.FullPath("/a")))
|
assert.Equal(t, true, tree.HasVisited(util.FullPath("/a")))
|
||||||
println(tree.HasVisited(util.FullPath("/g")))
|
assert.Equal(t, false, tree.HasVisited(util.FullPath("/g")))
|
||||||
println(tree.HasVisited(util.FullPath("/g/x")))
|
assert.Equal(t, false, tree.HasVisited(util.FullPath("/g/x")))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue