changelog

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 17, 2024 License: Apache-2.0 Imports: 2 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func NewChangelog[T comparable]() *Changelog[T]

NewChangelog creates a new changelog.

func (*Changelog[T]) Get

func (clv *Changelog[T]) Get(targetTime time.Time) T

Get returns the value of the changelog at the given time.

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]) Set

func (clv *Changelog[T]) Set(value T, targetTime time.Time)

Set sets the value of the changelog at the given time.

func (*Changelog[T]) SetCurrent

func (clv *Changelog[T]) SetCurrent(value T)

SetCurrent sets the latest value of the changelog.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL