collection

package
v2.0.437+incompatible Latest Latest
Warning

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

Go to latest
Published: May 5, 2018 License: AGPL-3.0 Imports: 3 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Now clock = func() int64 {
	return time.Now().UnixNano()
}

Now gets the current time in Unix nanoseconds

Functions

This section is empty.

Types

type BufferPool

type BufferPool struct {
	sync.Pool
}

BufferPool represents a thread safe buffer pool

func NewBufferPool

func NewBufferPool(bufferSize int) (bp *BufferPool)

NewBufferPool creates a new BufferPool bounded to the given size.

func (*BufferPool) Get

func (bp *BufferPool) Get() *bytes.Buffer

Get gets a Buffer from the SizedBufferPool, or creates a new one if none are available in the pool. Buffers have a pre-allocated capacity.

func (*BufferPool) Put

func (bp *BufferPool) Put(b *bytes.Buffer)

Put returns the given Buffer to the SizedBufferPool.

type LWWSet

type LWWSet struct {
	sync.Mutex
	Set LWWState
}

LWWSet represents a last-write-wins CRDT set.

func NewLWWSet

func NewLWWSet() *LWWSet

NewLWWSet creates a new last-write-wins set with bias for 'add'.

func (*LWWSet) Add

func (s *LWWSet) Add(value string)

Add adds a value to the set.

func (*LWWSet) All

func (s *LWWSet) All() LWWState

All gets all items in the set.

func (*LWWSet) Contains

func (s *LWWSet) Contains(value string) bool

Contains checks if a value is present in the set.

func (*LWWSet) GC

func (s *LWWSet) GC()

GC collects all the garbage in the set by simply removing it. This currently uses a very simplistic strategy with a static cutoff and expects all of the nodes in the cluster to have a relatively synchronized time, in absense of which this would cause inconsistency.

func (*LWWSet) Merge

func (s *LWWSet) Merge(r *LWWSet)

Merge merges two LWW sets. This also modifies the set being merged in to leave only the delta.

func (*LWWSet) Remove

func (s *LWWSet) Remove(value string)

Remove removes the value from the set.

type LWWState

type LWWState = map[string]LWWTime

LWWState represents the internal state

type LWWTime

type LWWTime struct {
	AddTime int64
	DelTime int64
}

LWWTime represents a time pair.

func (LWWTime) IsAdded

func (t LWWTime) IsAdded() bool

IsAdded checks if add time is larger than remove time.

func (LWWTime) IsRemoved

func (t LWWTime) IsRemoved() bool

IsRemoved checks if remove time is larger than add time.

func (LWWTime) IsZero

func (t LWWTime) IsZero() bool

IsZero checks if the time is zero

Jump to

Keyboard shortcuts

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