-
Notifications
You must be signed in to change notification settings - Fork 1
/
opts.go
38 lines (32 loc) · 979 Bytes
/
opts.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package skiplisttl
import (
"time"
"github.com/MauriceGit/skiplist"
)
// Opt allows to configure how TL behaves.
// See With... functions for details.
type Opt func(tl *TL)
// DefaultOpts contains the default configuration for a TL.
// This keys time at a millisecond resolution.
var DefaultOpts = []Opt{
WithSkipList(skiplist.New),
WithKeyFunc(func(t time.Time) float64 {
return float64(t.UnixMilli())
}),
}
// 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 WithKeyFunc(keyFunc KeyFunc) Opt {
return func(tl *TL) {
tl.key = keyFunc
}
}
// 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().
func WithSkipList(sl func() skiplist.SkipList) Opt {
return func(tl *TL) {
underlying := sl()
tl.items = &fixedSkipList{&underlying}
}
}