crdt

package module
v0.0.0-...-31de3c2 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2016 License: MIT Imports: 6 Imported by: 0

README

gocrdt

Convergent Replicated Data Types for Go

Implemenations follows the Specifications in

Shapiro, Preguica, Baquero, Zawirski: A comprehensive study of Convergent and Commutative Replicated Data Types

Since many other implementations fail: The Focus is on correctness, not performance.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorPreviouslyDeleted   = errors.New("Element was previusly removed, cannot be added animore")
	ErrorElementDoesNotExist = errors.New("Element does not exist in the set")
)

Functions

This section is empty.

Types

type GCounter

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

GCounter implements an State-based increment-only Counter (Specification 6)

func NewGCounter

func NewGCounter() *GCounter

NewGCounter is a constructor for a new GCounter

func (*GCounter) Compare

func (g *GCounter) Compare(other *GCounter) bool

Compare returns true, if call counters of g are <= the counters of other

func (*GCounter) Inc

func (g *GCounter) Inc()

Increases the Counter by 1

func (*GCounter) Merge

func (g *GCounter) Merge(other *GCounter) *GCounter

Merge merges counters g and other into a new counter

func (*GCounter) MergeFrom

func (g *GCounter) MergeFrom(other *GCounter)

func (*GCounter) Value

func (g *GCounter) Value() int

Count gives the current count

type GSet

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

GSet represents a State-based grow-only Set (G-Set, Specification 11)

func NewGSet

func NewGSet() *GSet

NewGSet constructs a new GSet

func (*GSet) Clone

func (gs *GSet) Clone() *GSet

Clone clones the GSet

func (*GSet) Compare

func (gs *GSet) Compare(other *GSet) bool

Compare compares if the GSet is a Subset of other

func (*GSet) Contains

func (gs *GSet) Contains(x interface{}) bool

Contains return if the given x is in the GSet

func (*GSet) Count

func (gs *GSet) Count() int

Count returns the number of elements in the GSet

func (*GSet) MarshalJSON

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

MarshalJSON returns a JSON representation of the GSet according to github.com/aphyr/meangirls

func (*GSet) Merge

func (gs *GSet) Merge(other *GSet) *GSet

Merge merges the GSet with other into a new GSet

func (*GSet) ToSlice

func (gs *GSet) ToSlice() []interface{}

ToSlice returns all the Elements of the GSet in a slice

func (*GSet) Update

func (gs *GSet) Update(x interface{})

Update adds the value to the GSet

type LwwRegister

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

LwwRegister implement a State-based Last-Writer Wins Register (Specification 8) Note that the CRDT properties only hold if the clocks are synchtronized such that the timestamp gives a total order of events. That does typically not hold for distributed systems and can even be problematic on a single machine.

func NewLwwRegister

func NewLwwRegister() *LwwRegister

func (*LwwRegister) Assign

func (l *LwwRegister) Assign(x interface{})

func (*LwwRegister) Compare

func (l *LwwRegister) Compare(other *LwwRegister) bool

Compare returns true, if l is older than other

func (*LwwRegister) Merge

func (l *LwwRegister) Merge(other *LwwRegister) *LwwRegister

Merge merges l and other into a new LwwRegister

func (*LwwRegister) MergeFrom

func (l *LwwRegister) MergeFrom(other *LwwRegister)

MergeFrom merges other into l

func (*LwwRegister) Value

func (l *LwwRegister) Value() interface{}

Value returns the assigned value of the LwwRegister

type LwwSet

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

LwwSet implements a Last-Write-Wins element Set CRDT (3.3.3, Figure 12) Be aware that the CRDT properties only holds if the clocks are synchronized such that the timestamps provide a total ordering of events

func NewLwwSet

func NewLwwSet() *LwwSet

func (*LwwSet) Add

func (l *LwwSet) Add(v interface{})

func (*LwwSet) Contains

func (l *LwwSet) Contains(v interface{}) bool

func (*LwwSet) Merge

func (l *LwwSet) Merge(other *LwwSet) *LwwSet

func (*LwwSet) MergeFrom

func (l *LwwSet) MergeFrom(other *LwwSet)

func (*LwwSet) Remove

func (l *LwwSet) Remove(v interface{})

type PNCounter

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

PNCounter impplementes a State-based PN-Counter (Specification 7)

func NewPNCounter

func NewPNCounter() *PNCounter

func (*PNCounter) Compare

func (pn *PNCounter) Compare(other *PNCounter) bool

Value returns if pn was before or the same time as other

func (*PNCounter) Dec

func (pn *PNCounter) Dec()

Dec decrements the PNCounter by one

func (*PNCounter) Inc

func (pn *PNCounter) Inc()

Inc increases the PNCounter by one

func (*PNCounter) Merge

func (pn *PNCounter) Merge(other *PNCounter) *PNCounter

Merge returns a new PNCounter merged from pn and other

func (*PNCounter) MergeFrom

func (pn *PNCounter) MergeFrom(other *PNCounter)

MergeFrom merges other into pn

func (*PNCounter) Value

func (pn *PNCounter) Value() int

Value returns the Value of the PNCounter

type Twopset

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

Twopset represents a State-based 2P-Set (Specification 12)

func NewTwopset

func NewTwopset() *Twopset

func (*Twopset) Add

func (t *Twopset) Add(x interface{}) error

func (*Twopset) Contains

func (t *Twopset) Contains(x interface{}) bool

func (*Twopset) Equals

func (t *Twopset) Equals(other *Twopset) bool

IsEqual return true if both sets are equal. The equality is strict: Borth the set and the removed elements have to be equal

func (*Twopset) Merge

func (t *Twopset) Merge(other *Twopset) *Twopset

func (*Twopset) MergeFrom

func (t *Twopset) MergeFrom(other *Twopset)

func (*Twopset) Remove

func (t *Twopset) Remove(x interface{}) error

type USet

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

USet implement an Op-base 2P-Set with unique elements (Specification 13) Value HAVE to be unique element like UUIDs or Lamport Clocks TODO: Think about how to implement the predonditions: x is unique, add(x) has been delivered

func (*USet) Contains

func (u *USet) Contains(x interface{}) bool

Jump to

Keyboard shortcuts

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