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)) {
121121
122122 for len (nodes ) != 0 {
123123 c := nodes [len (nodes )- 1 ]
124- fn (c .interval )
125124 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+ }
131133 }
132134 }
133135}
Original file line number Diff line number Diff line change @@ -625,6 +625,11 @@ func TestInsertDuplicateIntervalChildren(t *testing.T) {
625625
626626func TestTraverse (t * testing.T ) {
627627 tree := newTree (1 )
628+
629+ tree .Traverse (func (i Interval ) {
630+ assert .Fail (t , `traverse should not be called for empty tree` )
631+ })
632+
628633 top := 30
629634 for i := 0 ; i <= top ; i ++ {
630635 tree .Add (constructSingleDimensionInterval (int64 (i * 10 ), int64 ((i + 1 )* 10 ), uint64 (i )))
You can’t perform that action at this time.
0 commit comments