فهرست منبع

Merge pull request #6601 from nekto0n/interval_tree_fast_stab

adt: fast path Stab in empty interval tree
Xiang Li 9 سال پیش
والد
کامیت
e2bd6f2213
1فایلهای تغییر یافته به همراه3 افزوده شده و 0 حذف شده
  1. 3 0
      pkg/adt/interval_tree.go

+ 3 - 0
pkg/adt/interval_tree.go

@@ -447,6 +447,9 @@ func (ivt *IntervalTree) Contains(iv Interval) bool {
 
 // Stab returns a slice with all elements in the tree intersecting the interval.
 func (ivt *IntervalTree) Stab(iv Interval) (ivs []*IntervalValue) {
+	if ivt.count == 0 {
+		return nil
+	}
 	f := func(n *IntervalValue) bool { ivs = append(ivs, n); return true }
 	ivt.Visit(iv, f)
 	return ivs