dt

package module
v0.0.0-...-3af3e84 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2021 License: BSD-2-Clause Imports: 7 Imported by: 0

README

dt: CRDT in Golang

  • GSset
  • GCounter
  • LWWReg
  • ORSet
  • Vector Clock

License

dt is developed under the BSD-2-Clause License.

Documentation

Index

Constants

View Source
const DEFAULT_BIG_VCLOCK = 50
View Source
const DEFAULT_OLD_VCLOCK = 86400
View Source
const DEFAULT_SMALL_VCLOCK = 50
View Source
const DEFAULT_YOUNG_VCLOCK = 20

Variables

This section is empty.

Functions

func GetBigVclock

func GetBigVclock(prop map[string]int) int

func GetOldVclock

func GetOldVclock(prop map[string]int) int

func GetParams

func GetParams(d map[string]int, key string, default_value int) int

func GetSmallVclock

func GetSmallVclock(prop map[string]int) int

func GetYoungVclock

func GetYoungVclock(prop map[string]int) int

Types

type DVV

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

Individual event with timestamp

func NewDVV

func NewDVV() DVV

Instantiate a new DVV struct

func (DVV) Descends

func (va DVV) Descends(vb DVV) bool

Return true if the vclock va is a direct descendant of vclock vb, else false.

func (DVV) Dominates

func (va DVV) Dominates(vb DVV) bool

true if vclock va strictly dominates vclock vb. Note: ignores timestamps In riak it is possible to have vclocks that are identical except for timestamps. when two vclocks descend each other, but are not equal, they are concurrent. See source comment for more details.

func (*DVV) GetCounter

func (v *DVV) GetCounter(id string) uint32

Get the counter value in a DVV set from node

func (*DVV) GetDot

func (v *DVV) GetDot(id string) (*Dot, error)

Get the timestamp value in a DVV set from node

func (*DVV) GetTimestamp

func (v *DVV) GetTimestamp(id string) (uint32, error)

Get the timestamp value in a DVV set from node

func (*DVV) Increment

func (v *DVV) Increment(node string)

Increment vclock at Node

func (DVV) Len

func (d DVV) Len() int

For sort. Returns length of vector of the dvv

func (DVV) Less

func (d DVV) Less(i, j int) bool

For sort. Returns the result of compare two node

func (*DVV) Merge

func (v *DVV) Merge(vclocks []DVV)

Combine all vclocks in the input list in to their least possible common descendant.

func (*DVV) Prune

func (v *DVV) Prune(now uint32, props map[string]int)

Possibly shrink the size of a vclock, depending on current age and size.

func (DVV) Swap

func (d DVV) Swap(i, j int)

For sort. Swap element

type Dot

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

Timestamp of individual event

type GCounter

type GCounter struct {
	Counters map[string]uint
}

func NewGCounter

func NewGCounter() GCounter

Create a new gcounter

func (GCounter) AllNode

func (counter GCounter) AllNode(counters []GCounter) []string

Returns the list of all nodes that have ever incremneted counter

func (GCounter) Equal

func (counter_a GCounter) Equal(counter_b GCounter) bool

Compare two counter for equality

func (*GCounter) Increment

func (counter *GCounter) Increment(node string)

increment counter for the node by 1

func (*GCounter) IncrementBy

func (counter *GCounter) IncrementBy(node string, amount uint)

perform the increment

func (*GCounter) Merge

func (counter_a *GCounter) Merge(counters []GCounter)

Combine all counters in the input list uinto a map

func (GCounter) Value

func (counter GCounter) Value() uint

The single total value of a gcounter

type GSet

type GSet struct {
	Set map[string]bool
}

func NewGSet

func NewGSet() GSet

Create a new gset

func (*GSet) Add

func (gset *GSet) Add(elem string)

append an element to the set

func (GSet) Equal

func (gset_a GSet) Equal(gset_b GSet) bool

Compair Two set for equality

func (GSet) Exists

func (gset GSet) Exists(elem string) bool

return true if the element exists in the set

func (*GSet) Values

func (gset *GSet) Values() []string

Returns a set of value.

type LWWReg

type LWWReg struct {
	Value     string
	Timestamp int64
}

func NewLWWReg

func NewLWWReg() LWWReg

Create a new empty lwwreg

func (*LWWReg) Assign

func (reg *LWWReg) Assign(value string)

Assign a value to the lwwreg associating the update with time ts

func (*LWWReg) AssignTS

func (reg *LWWReg) AssignTS(value string, ts int64)

func (LWWReg) Equal

func (reg_a LWWReg) Equal(reg_b LWWReg) bool

Are two lwwreg s structurally equal? this is not value equality. Two regsiters might represent the value armchair and not be equal(). Equality here is that both registers contain the same value and timestamp

func (*LWWReg) Merge

func (reg_a *LWWReg) Merge(reg_b LWWReg)

Merge two lwwreg to a single lwwreg. this is the least upper bound function described in the literature

type ORSet

type ORSet struct {
	Set map[string]Token
}

func NewOrset

func NewOrset() ORSet

Create a new ORSet

func (ORSet) Lookup

func (orset ORSet) Lookup(elem string) bool

func (ORSet) RemovedValue

func (orset ORSet) RemovedValue() []string

Return values which has removed

func (ORSet) Token

func (orset ORSet) Token(elem string) (Token, error)

func (ORSet) Value

func (orset ORSet) Value() []string

Return values which hasn't removed only

type Token

type Token struct {
	Tag       int
	IsRemoved bool
}

Jump to

Keyboard shortcuts

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