Documentation
¶
Overview ¶
Package skiplisttl provides a skip list based implementation of timeline.TL.
Index ¶
- Variables
- type KeyFunc
- type Opt
- type TL
- func (tl *TL) Add(t time.Time, entries ...interface{})
- func (tl *TL) At(t time.Time) []interface{}
- func (tl *TL) Bound() (first, last time.Time, exists bool)
- func (tl *TL) Empty() bool
- func (tl *TL) Next(t time.Time) (next time.Time, exists bool)
- func (tl *TL) Previous(t time.Time) (previous time.Time, exists bool)
- func (tl *TL) Remove(t time.Time, entries ...interface{})
Examples ¶
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
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 ¶
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)