skiplisttl

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package skiplisttl provides a skip list based implementation of timeline.TL.

Index

Examples

Constants

This section is empty.

Variables

View Source
var DefaultOpts = []Opt{
	WithSkipList(skiplist.New),
	WithKeyFunc(func(t time.Time) float64 {
		return float64(t.UnixMilli())
	}),
}

DefaultOpts contains the default configuration for a TL. This keys time at a millisecond resolution.

Functions

This section is empty.

Types

type KeyFunc

type KeyFunc func(t time.Time) float64

KeyFunc converts a time.Time into a float64 used as a key in the underlying skip list.

type Opt

type Opt func(tl *TL)

Opt allows to configure how TL behaves. See With... functions for details.

func WithKeyFunc

func WithKeyFunc(keyFunc KeyFunc) Opt

WithKeyFunc configures the TL to use this function to convert time.Time into float64 keys for the skip list. The default is to use Time.UnixMilli().

func WithSkipList

func WithSkipList(sl func() skiplist.SkipList) Opt

WithSkipList allows you to provide a customised version of the underlying skiplist.SkipList. Typically used to set a seed for testing. Defaults to skiplist.New().

type TL

type TL struct {
	// contains filtered or unexported fields
}

TL is an implementation of timeline.TL backed by a skip list. The TL is writable and any timeline.Slice or timeline.Filter applied to this TL will reflect changes, but will not be writable themselves.

Example
t1 := time.Date(2022, 02, 03, 15, 40, 10, 0, time.UTC)
t2 := time.Date(2021, 12, 10, 8, 20, 0, 0, time.UTC)

tl := New()
tl.Add(t1, "A-1", "A-2")
tl.Add(t2, "B")

start, end, _ := timeline.Bound(tl)
fmt.Printf("TL Bounds [%v, %v)", start, end)
Output:

TL Bounds [2021-12-10 08:20:00 +0000 UTC, 2022-02-03 15:40:10 +0000 UTC)

func New

func New(opts ...Opt) *TL

New creates a new TL. See DefaultOpts for the default Opts applied to new instances.

func (*TL) Add

func (tl *TL) Add(t time.Time, entries ...interface{})

func (*TL) At

func (tl *TL) At(t time.Time) []interface{}

func (*TL) Bound

func (tl *TL) Bound() (first, last time.Time, exists bool)

func (*TL) Empty

func (tl *TL) Empty() bool

func (*TL) Next

func (tl *TL) Next(t time.Time) (next time.Time, exists bool)

func (*TL) Previous

func (tl *TL) Previous(t time.Time) (previous time.Time, exists bool)

func (*TL) Remove

func (tl *TL) Remove(t time.Time, entries ...interface{})

Jump to

Keyboard shortcuts

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