Skip to content

Commit

Permalink
Rename walk
Browse files Browse the repository at this point in the history
  • Loading branch information
Menno Pruijssers committed Dec 14, 2016
1 parent 5e842da commit bfb5e86
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
12 changes: 6 additions & 6 deletions hashring/rbtree.go
Expand Up @@ -261,28 +261,28 @@ func (n *redBlackNode) search(key keytype) (valuetype, bool) {
return nil, false
}

// walk Walks the tree in sorted order invoking `walker` for each node. If the
// walker function returns `false`, walking is stopped and no more nodes will be
// traverseUntil traverses the nodes in the tree in-order invoking `traverse` for each node. If the
// traverse function returns `false`, traversal is stopped and no more nodes will be
// visited. Returns `true` if all nodes are visited; `false` if not.
func (n *redBlackNode) walk(walker func(*redBlackNode) bool) bool {
func (n *redBlackNode) traverseUntil(traverse func(*redBlackNode) bool) bool {
if n == nil {
// the end of the tree does not signal the end of walking, but we can't
// walk this node (nil) nor left or right anymore
return true
}

// walk left first
if !n.left.walk(walker) {
if !n.left.traverseUntil(traverse) {
// stop if walker indicated to break
return false
}
// now visit this node
if !walker(n) {
if !traverse(n) {
// stop if walker indicated to break
return false
}
// lastly visit right
if !n.right.walk(walker) {
if !n.right.traverseUntil(traverse) {
// stop if walker indicated to break
return false
}
Expand Down
8 changes: 4 additions & 4 deletions hashring/rbtree_test.go
Expand Up @@ -637,7 +637,7 @@ func TestBig(t *testing.T) {
assert.NoError(t, err, "expected tree to be a valid red black tree")
}

func TestWalkInOrder(t *testing.T) {
func TestTraverseOrder(t *testing.T) {
tree := makeTree()

// 4,B
Expand All @@ -650,7 +650,7 @@ func TestWalkInOrder(t *testing.T) {

var last keytype

tree.root.walk(func(n *redBlackNode) bool {
tree.root.traverseUntil(func(n *redBlackNode) bool {
current := n.key
if last != nil {
assert.True(t, current.Compare(last) > 0, "expected walk to walk the nodes in natural order as dictated by the Compare function")
Expand All @@ -660,7 +660,7 @@ func TestWalkInOrder(t *testing.T) {
})
}

func TestWalkEscape(t *testing.T) {
func TestTraverseEscape(t *testing.T) {
tree := makeTree()

// 4,B
Expand All @@ -673,7 +673,7 @@ func TestWalkEscape(t *testing.T) {

var visited []int

tree.root.walk(func(n *redBlackNode) bool {
tree.root.traverseUntil(func(n *redBlackNode) bool {
number := int(n.key.(treeTestInt))
visited = append(visited, number)
// stop at node 5, it should exit on a left, right and visiting node,
Expand Down

0 comments on commit bfb5e86

Please sign in to comment.