MCPcopy Create free account
hub / github.com/google/gapid / intersect

Method intersect

core/math/interval/algorithm.go:63–94  ·  view source on GitHub ↗

intersect a span with a list, calculating the intersection span and interval range

(l List, span U64Span, expand bool)

Source from the content-addressed store, hash-verified

61
62// intersect a span with a list, calculating the intersection span and interval range
63func (s *intersection) intersect(l List, span U64Span, expand bool) {
64 var beforeLen, afterIndex int
65 if expand {
66 beforeLen = search(l, func(test U64Span) bool {
67 return span.Start <= test.End
68 })
69 afterIndex = search(l, func(test U64Span) bool {
70 return span.End < test.Start
71 })
72 } else {
73 beforeLen = search(l, func(test U64Span) bool {
74 return span.Start < test.End
75 })
76 afterIndex = search(l, func(test U64Span) bool {
77 return span.End <= test.Start
78 })
79 }
80 if afterIndex < beforeLen {
81 afterIndex, beforeLen = beforeLen, afterIndex
82 }
83 s.lowIndex = beforeLen
84 s.highIndex = afterIndex - 1
85 s.overlap = afterIndex - beforeLen
86 s.intersectsLow = false
87 s.intersectsHigh = false
88 if s.overlap > 0 {
89 s.low = l.GetSpan(s.lowIndex)
90 s.intersectsLow = s.low.Start < span.Start
91 s.high = l.GetSpan(s.highIndex)
92 s.intersectsHigh = span.End < s.high.End
93 }
94}
95
96// merges a new span into a list, returning the index of the span
97func merge(l MutableList, span U64Span, joinAdj bool) int {

Callers 3

mergeFunction · 0.95
cutFunction · 0.95
IntersectFunction · 0.95

Calls 2

searchFunction · 0.85
GetSpanMethod · 0.65

Tested by

no test coverage detected