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 Durable

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

Durable represents a last-write-wins CRDT set which can be persisted to disk.

func NewDurable

func NewDurable(dir string) *Durable

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

func (*Durable) Add

func (s *Durable) Add(item string, value []byte)

Add adds a value to the set.

func (*Durable) Close

func (s *Durable) Close() error

Close closes the set gracefully.

func (*Durable) Count

func (s *Durable) Count() (count int)

Count returns the number of items in the set.

func (*Durable) Del

func (s *Durable) Del(item string)

Del removes the value from the set.

func (*Durable) Get

func (s *Durable) Get(item string) Value

Get retrieves the time for an item.

func (*Durable) GetBinaryCodec

func (s *Durable) GetBinaryCodec() binary.Codec

GetBinaryCodec retrieves a custom binary codec.

func (*Durable) Has

func (s *Durable) Has(item string) bool

Has checks if a value is present in the set.

func (*Durable) Merge

func (s *Durable) Merge(other Map)

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

func (*Durable) Range

func (s *Durable) Range(prefix []byte, tombstones bool, f func(string, Value) bool)

Range iterates through the events for a specific prefix.

type Map

type Map interface {
	Add(string, []byte)
	Del(string)
	Has(string) bool
	Get(string) Value
	Merge(Map)
	Range([]byte, bool, func(string, Value) bool)
	Count() int
}

Map represents a contract for a CRDT map.

func New

func New(durable bool, path string) Map

New creates a new CRDT map.

type Value

type Value []byte

Value represents a time pair with a value.

func (Value) AddTime

func (v Value) AddTime() int64

AddTime returns when the entry was added.

func (Value) DelTime

func (v Value) DelTime() int64

DelTime returns when the entry was removed.

func (Value) IsAdded

func (v Value) IsAdded() bool

IsAdded checks if add time is larger than remove time.

func (Value) IsRemoved

func (v Value) IsRemoved() bool

IsRemoved checks if remove time is larger than add time.

func (Value) IsZero

func (v Value) IsZero() bool

IsZero checks if the time is zero

func (Value) Value

func (v Value) Value() []byte

Value returns the extra value payload.

type Volatile

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

Volatile represents a last-write-wins CRDT set.

func NewVolatile

func NewVolatile() *Volatile

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

func (*Volatile) Add

func (s *Volatile) Add(item string, value []byte)

Add adds a value to the set.

func (*Volatile) Count

func (s *Volatile) Count() (count int)

Count returns the number of items in the set.

func (*Volatile) Del

func (s *Volatile) Del(item string)

Del removes the value from the set.

func (*Volatile) Get

func (s *Volatile) Get(item string) Value

Get retrieves the time for an item.

func (*Volatile) GetBinaryCodec

func (s *Volatile) GetBinaryCodec() binary.Codec

GetBinaryCodec retrieves a custom binary codec.

func (*Volatile) Has

func (s *Volatile) Has(item string) bool

Has checks if a value is present in the set.

func (*Volatile) Merge

func (s *Volatile) Merge(other Map)

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

func (*Volatile) Range

func (s *Volatile) Range(prefix []byte, tombstones bool, f func(string, Value) bool)

Range iterates through the events for a specific prefix.