Browse Source

adt: Union for interval trees

Anthony Romano 8 năm trước cách đây
mục cha
commit
5c7efaa288
1 tập tin đã thay đổi với 9 bổ sung0 xóa
  1. 9 0
      pkg/adt/interval_tree.go

+ 9 - 0
pkg/adt/interval_tree.go

@@ -485,6 +485,15 @@ func (ivt *IntervalTree) Stab(iv Interval) (ivs []*IntervalValue) {
 	return ivs
 }
 
+// Union merges a given interval tree into the receiver.
+func (ivt *IntervalTree) Union(inIvt IntervalTree, ivl Interval) {
+	f := func(n *IntervalValue) bool {
+		ivt.Insert(n.Ivl, n.Val)
+		return true
+	}
+	inIvt.Visit(ivl, f)
+}
+
 type StringComparable string
 
 func (s StringComparable) Compare(c Comparable) int {