// visitLevel traverses tree in level order.
// used for testing
visitLevel traverses tree in level order.
used for testing
// visitLevel traverses tree in level order . // used for testing
func (ivt *intervalTree) visitLevel() []visitedInterval {
	if ivt.root == ivt.nilNode {
		return nil
	}
	rs := make([]visitedInterval, 0, ivt.Len())
	type pair struct {
		node  *intervalNode
		depth int
	}
	queue := []pair{{ivt.root, 0}}
	for len(queue) > 0 {
		f := queue[0]
		queue = queue[1:]
		ivt2 := visitedInterval{
			root:  f.node.iv.Ivl,
			color: f.node.color(ivt.nilNode),
			depth: f.depth,
		}
		if f.node.left != ivt.nilNode {
			ivt2.left = f.node.left.iv.Ivl
			queue = append(queue, pair{f.node.left, f.depth + 1})
		}
		if f.node.right != ivt.nilNode {
			ivt2.right = f.node.right.iv.Ivl
			queue = append(queue, pair{f.node.right, f.depth + 1})
		}
		rs = append(rs, ivt2)
	}
	return rs
}
func ( ivt * intervalTree ) visitLevel ( ) [ ] visitedInterval { if ivt . root == ivt . nilNode { return nil } rs := make ( [ ] visitedInterval , 0 , ivt . Len ( ) ) type pair struct { node * intervalNode depth int } queue := [ ] pair { { ivt . root , 0 } } for len ( queue ) > 0 { f := queue [ 0 ] queue = queue [ 1 : ] ivt2 := visitedInterval { root : f . node . iv . Ivl , color : f . node . color ( ivt . nilNode ) , depth : f . depth , } if f . node . left != ivt . nilNode { ivt2 . left = f . node . left . iv . Ivl queue = append ( queue , pair { f . node . left , f . depth + 1 } ) } if f . node . right != ivt . nilNode { ivt2 . right = f . node . right . iv . Ivl queue = append ( queue , pair { f . node . right , f . depth + 1 } ) } rs = append ( rs , ivt2 ) } return rs }
visitLevel traverses tree in level order.
visitLevel traverses tree in level order .