crdt: github.com/neurodrone/crdt Index | Files

package crdt

import "github.com/neurodrone/crdt"

Index

Package Files

g_counter.go g_set.go lww_e_set.go or_set.go pn_counter.go set.go twophase_set.go

Variables

var (
    ErrNoSuchBias = errors.New("no such bias found")
)

type BiasType Uses

type BiasType string
const (
    BiasAdd    BiasType = "a"
    BiasRemove BiasType = "r"
)

type GCounter Uses

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

GCounter represent a G-counter in CRDT, which is a state-based grow-only counter that only supports increments.

func NewGCounter Uses

func NewGCounter() *GCounter

NewGCounter returns a *GCounter by pre-assigning a unique identity to it.

func (*GCounter) Count Uses

func (g *GCounter) Count() (total int)

Count returns the total count of this counter across all the present replicas.

func (*GCounter) Inc Uses

func (g *GCounter) Inc()

Inc increments the GCounter by the value of 1 everytime it is called.

func (*GCounter) IncVal Uses

func (g *GCounter) IncVal(incr int)

IncVal allows passing in an arbitrary delta to increment the current value of counter by. Only positive values are accepted. If a negative value is provided the implementation will panic.

func (*GCounter) Merge Uses

func (g *GCounter) Merge(c *GCounter)

Merge combines the counter values across multiple replicas. The property of idempotency is preserved here across multiple merges as when no state is changed across any replicas, the result should be exactly the same everytime.

type GSet Uses

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

Gset is a grow-only set.

func NewGSet Uses

func NewGSet() *GSet

NewGSet returns an instance of GSet.

func (*GSet) Add Uses

func (g *GSet) Add(elem interface{})

Add lets you add an element to grow-only set.

func (*GSet) Contains Uses

func (g *GSet) Contains(elem interface{}) bool

Contains returns true if an element exists within the set or false otherwise.

func (*GSet) Elems Uses

func (g *GSet) Elems() []interface{}

Elems returns all the elements present in the set.

func (*GSet) Len Uses

func (g *GSet) Len() int

Len returns the no. of elements present within GSet.

func (*GSet) MarshalJSON Uses

func (g *GSet) MarshalJSON() ([]byte, error)

MarshalJSON will be used to generate a serialized output of a given GSet.

type LWWSet Uses

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

func NewLWWSet Uses

func NewLWWSet() (*LWWSet, error)

func NewLWWSetWithBias Uses

func NewLWWSetWithBias(bias BiasType) (*LWWSet, error)

func (*LWWSet) Add Uses

func (s *LWWSet) Add(value interface{})

func (*LWWSet) Contains Uses

func (s *LWWSet) Contains(value interface{}) bool

func (*LWWSet) MarshalJSON Uses

func (s *LWWSet) MarshalJSON() ([]byte, error)

func (*LWWSet) Merge Uses

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

func (*LWWSet) Remove Uses

func (s *LWWSet) Remove(value interface{})

type ORSet Uses

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

func NewORSet Uses

func NewORSet() *ORSet

func (*ORSet) Add Uses

func (o *ORSet) Add(value interface{})

func (*ORSet) Contains Uses

func (o *ORSet) Contains(value interface{}) bool

func (*ORSet) Merge Uses

func (o *ORSet) Merge(r *ORSet)

func (*ORSet) Remove Uses

func (o *ORSet) Remove(value interface{})

type PNCounter Uses

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

PNCounter represents a state-based PN-Counter. It is implemented as sets of two G-Counters, one that tracks increments while the other decrements.

func NewPNCounter Uses

func NewPNCounter() *PNCounter

NewPNCounter returns a new *PNCounter with both its G-Counters initialized.

func (*PNCounter) Count Uses

func (pn *PNCounter) Count() int

Count returns the current value of the counter. It subtracts the value of negative G-Counter from the positive grow-only counter and returns the result. Because this counter can grow in either direction, negative integers as results are possible.

func (*PNCounter) Dec Uses

func (pn *PNCounter) Dec()

Dec monotonically decrements the current value of the PN-Counter by one.

func (*PNCounter) DecVal Uses

func (pn *PNCounter) DecVal(decr int)

DecVal adds a decrement to the current value of PN-Counter by the value of delta decr. Similar to IncVal, the value of decr cannot be less than 0.

func (*PNCounter) Inc Uses

func (pn *PNCounter) Inc()

Inc monotonically increments the current value of the PN-Counter by one.

func (*PNCounter) IncVal Uses

func (pn *PNCounter) IncVal(incr int)

IncVal increments the current value of the PN-Counter by the delta incr that is provided. The value of delta has to be >= 0. If the value of delta is < 0, then this implementation panics.

func (*PNCounter) Merge Uses

func (pn *PNCounter) Merge(pnpn *PNCounter)

Merge combines both the PN-Counters and saves the result in the invoking counter. Respective G-Counters are merged i.e. +ve with +ve and -ve with -ve, but not computation is actually performed.

type Set Uses

type Set interface {
    Add(interface{})
    Contains(interface{}) bool
}

type TwoPhaseSet Uses

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

TwoPhaseSet supports both addition and removal of elements to set.

func NewTwoPhaseSet Uses

func NewTwoPhaseSet() *TwoPhaseSet

NewTwoPhaseSet returns a new instance of TwoPhaseSet.

func (*TwoPhaseSet) Add Uses

func (t *TwoPhaseSet) Add(elem interface{})

Add inserts element into the TwoPhaseSet.

func (*TwoPhaseSet) Contains Uses

func (t *TwoPhaseSet) Contains(elem interface{}) bool

Contains returns true if the set contains the element. The set is said to contain the element if it is present in the add-set and not in the remove-set.

func (*TwoPhaseSet) MarshalJSON Uses

func (t *TwoPhaseSet) MarshalJSON() ([]byte, error)

MarshalJSON serializes TwoPhaseSet into an JSON array.

func (*TwoPhaseSet) Remove Uses

func (t *TwoPhaseSet) Remove(elem interface{})

Remove deletes the element from the set.

Package crdt imports 5 packages (graph). Updated 2019-04-17. Refresh now. Tools for package owners.