github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/pkg/storage/segment/relationship.go (about) 1 package segment 2 3 import ( 4 "time" 5 ) 6 7 type rel int 8 9 const ( 10 // relationship overlap read overlap write 11 inside rel = iota // | S E | <1 1/1 12 match // matching ranges 1/1 1/1 13 outside // | | S E 0/1 0/1 14 overlap // | S | E <1 <1 15 contain // S | | E 1/1 <1 16 ) 17 18 var overlapStrings map[rel]string 19 20 // TODO: I bet there's a better way 21 func init() { 22 overlapStrings = make(map[rel]string) 23 overlapStrings[inside] = "inside" 24 overlapStrings[outside] = "outside" 25 overlapStrings[match] = "match" 26 overlapStrings[overlap] = "overlap" 27 overlapStrings[contain] = "contain" 28 } 29 30 func (r rel) String() string { 31 return overlapStrings[r] 32 } 33 34 // t1, t2 represent segment node, st, et represent the read/write query time range 35 func relationship(t1, t2, st, et time.Time) rel { 36 if t1.Equal(st) && t2.Equal(et) { 37 return match 38 } 39 if !t1.After(st) && !t2.Before(et) { 40 return inside 41 } 42 if !t1.Before(st) && !t2.After(et) { 43 return contain 44 } 45 if !t1.After(st) && !t2.After(st) { 46 return outside 47 } 48 if !t1.Before(et) && !t2.Before(et) { 49 return outside 50 } 51 52 return overlap 53 }