Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Changelog ¶
type Changelog[T comparable] struct {
// contains filtered or unexported fields
}
func NewChangelog ¶
NewChangelog creates a new changelog.
func (*Changelog[T]) GetAll ¶
func (clv *Changelog[T]) GetAll() []T
GetAll returns all the values of the changelog.
func (*Changelog[T]) GetCurrent ¶
func (clv *Changelog[T]) GetCurrent() T
GetCurrent: Observation on single element changelog.
If there's one element in the changelog, after the loop, left would be set to 1 if the single timestamp is before the targetTime, and 0 if it's equal or after.
BEFORE: If the single timestamp is before the targetTime, when we return clv.changes[left-1].value, returns clv.changes[0].value, which is the expected behavior.
AFTER: If the single timestamp is equal to, or after the targetTime, the current logic would return a "zero" value because of the condition if left == 0.
We need to find the last change that occurred before or exactly at the targetTime. The binary search loop finds the position where a new entry with the targetTime timestamp would be inserted to maintain chronological order:
This position is stored in "left".
So, to get the last entry that occurred before the targetTime, we need to access the previous position, which is left-1.
GetCurrent returns the latest value of the changelog.
func (*Changelog[T]) SetCurrent ¶
func (clv *Changelog[T]) SetCurrent(value T)
SetCurrent sets the latest value of the changelog.