File tree Expand file tree Collapse file tree 2 files changed +13
-6
lines changed Expand file tree Collapse file tree 2 files changed +13
-6
lines changed Original file line number Diff line number Diff line change @@ -121,13 +121,15 @@ func (t *tree) Traverse(fn func(id Interval)) {
121
121
122
122
for len (nodes ) != 0 {
123
123
c := nodes [len (nodes )- 1 ]
124
- fn (c .interval )
125
124
nodes = nodes [:len (nodes )- 1 ]
126
- if c .children [0 ] != nil {
127
- nodes = append (nodes , c .children [0 ])
128
- }
129
- if c .children [1 ] != nil {
130
- nodes = append (nodes , c .children [1 ])
125
+ if c != nil {
126
+ fn (c .interval )
127
+ if c .children [0 ] != nil {
128
+ nodes = append (nodes , c .children [0 ])
129
+ }
130
+ if c .children [1 ] != nil {
131
+ nodes = append (nodes , c .children [1 ])
132
+ }
131
133
}
132
134
}
133
135
}
Original file line number Diff line number Diff line change @@ -625,6 +625,11 @@ func TestInsertDuplicateIntervalChildren(t *testing.T) {
625
625
626
626
func TestTraverse (t * testing.T ) {
627
627
tree := newTree (1 )
628
+
629
+ tree .Traverse (func (i Interval ) {
630
+ assert .Fail (t , `traverse should not be called for empty tree` )
631
+ })
632
+
628
633
top := 30
629
634
for i := 0 ; i <= top ; i ++ {
630
635
tree .Add (constructSingleDimensionInterval (int64 (i * 10 ), int64 ((i + 1 )* 10 ), uint64 (i )))
You can’t perform that action at this time.
0 commit comments