Documentation
¶
Index ¶
- type Boundary
- type Property
- type PropertyEqualFn
- type T
- func (t *T[B, P]) All() iter.Seq2[axisds.Interval[B], P]
- func (t *T[B, P]) AllWithGC() iter.Seq2[axisds.Interval[B], P]
- func (t *T[B, P]) Any(start, end B, propFn func(prop P) bool) bool
- func (t *T[B, P]) AnyWithGC(start, end B, propFn func(prop P) bool) bool
- func (t *T[B, P]) CheckInvariants()
- func (t *T[B, P]) Clone() T[B, P]
- func (t *T[B, P]) Enumerate(start, end B) iter.Seq2[axisds.Interval[B], P]
- func (t *T[B, P]) EnumerateWithGC(start, end B) iter.Seq2[axisds.Interval[B], P]
- func (t *T[B, P]) InternalLen() int
- func (t *T[B, P]) IsEmpty() bool
- func (t *T[B, P]) String(iFmt axisds.IntervalFormatter[B]) string
- func (t *T[B, P]) Update(start, end B, updateProp func(p P) P)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Property ¶
type Property any
Property is an arbitrary type that represents a property of a region of a one-dimensional axis.
type PropertyEqualFn ¶
PropertyEqualFn is a function used to compare properties of two regions. If it returns true, the two property values can be used interchangeably.
Note that it is allowed for the function to "evolve" over time (but not concurrently with a region tree method), with values that were not equal becoming equal (but not the opposite: once two values are equal, they must stay equal forever). For example, the property can be a monotonic expiration time and as we update the current time, expired times become equal to the zero property.
A zero property value is any value that is equal to the zero P value.
type T ¶
T is a tree of regions which fragment a one-dimensional space. Regions have boundaries of type B and each region maintains a property P. Neighboring regions with equal properties are automatically merged.
T supports lazy (copy-on-write) cloning via Clone().
func Make ¶
Make creates a new region tree with the given boundary and property comparison functions.
func (*T[B, P]) All ¶
All emits all regions with non-zero property.
Two consecutive regions can "touch" but not overlap; if they touch, their properties are not equal.
All can be called concurrently with other read-only methods.
func (*T[B, P]) AllWithGC ¶
AllWithGC is a variant of All which internally deletes unnecessary boundaries between regions with properties that have become equal.
This variant is only useful to improve performance when the PropertyEqualFn can change over time. It cannot be called concurrently with any other methods.
func (*T[B, P]) Any ¶
Any returns true if [start, end) overlaps any region with property that satisfies the given function.
Any can be called concurrently with other read-only methods.
func (*T[B, P]) AnyWithGC ¶
AnyWithGC is a variant of Any which internally deletes unnecessary boundaries between regions with properties that have become equal.
This variant is only useful to improve performance when the PropertyEqualFn can change over time. It cannot be called concurrently with any other methods.
func (*T[B, P]) CheckInvariants ¶
func (t *T[B, P]) CheckInvariants()
CheckInvariants can be used in testing builds to verify internal invariants.
func (*T[B, P]) Clone ¶
Clone creates a lazy clone of T with the same properties and regions. The new tree can be modified independently.
This operation is constant time; it can cause some minor slowdown of future updates because of copy-on-write logic.
func (*T[B, P]) Enumerate ¶
Enumerate all regions in the range [start, end) with non-zero property.
Two consecutive regions can "touch" but not overlap; if they touch, their properties are not equal.
Enumerate can be called concurrently with other read-only methods.
func (*T[B, P]) EnumerateWithGC ¶
EnumerateWithGC is a variant of Enumerate which internally deletes unnecessary boundaries between regions with properties that have become equal.
This variant is only useful to improve performance when the PropertyEqualFn can change over time. It cannot be called concurrently with any other methods.
func (*T[B, P]) InternalLen ¶
InternalLen returns the number of region boundaries stored internally.
func (*T[B, P]) IsEmpty ¶
IsEmpty returns true if the tree contains no regions with non-zero property.
func (*T[B, P]) String ¶
func (t *T[B, P]) String(iFmt axisds.IntervalFormatter[B]) string
String formats all regions, one per line.
func (*T[B, P]) Update ¶
func (t *T[B, P]) Update(start, end B, updateProp func(p P) P)
Update the property for the given range. The updateProp function is called for all the regions within the range to calculate the new property.
The runtime complexity is O(log N + K) where K is the number of regions we are updating. Note that if the ranges we update are mostly non-overlapping, this will be O(log N) on average.