Documentation ¶
Index ¶
- Constants
- type Config
- type MergeError
- type MergeFunc
- type OnConflictMerged
- type Root
- type Tree
- func (c Tree) Clone(ctx context.Context) (*Tree, error)
- func (c *Tree) Get(ctx context.Context, key interface{}, value interface{}) (bool, error)
- func (c Tree) IsDirty() bool
- func (c *Tree) IsTombstoned(ctx context.Context, key interface{}) (bool, error)
- func (c *Tree) MakeRoot(ctx context.Context) (*Root, error)
- func (c *Tree) Merge(ctx context.Context, other *Tree) error
- func (c *Tree) Set(ctx context.Context, when time.Time, key, value interface{}) error
- func (c *Tree) Size() uint64
- func (c *Tree) Tombstone(ctx context.Context, when time.Time, key interface{}) error
Constants ¶
View Source
const ( MergeModeLWW = iota MergeModeCustom MergeModeCustomLWW )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { KeysLike interface{} ValuesLike interface{} StoreImmutablePartsWith mast.Persist NodeCache mast.NodeCache Marshal func(interface{}) ([]byte, error) Unmarshal func([]byte, interface{}) error UnmarshalerUsesRegisteredTypes bool CustomMerge func(key interface{}, v1, v2 crdt.Value) crdt.Value OnConflictMerged MastNodeFormat string }
type MergeError ¶
type MergeError error
type MergeFunc ¶
type MergeFunc func(context.Context, *mast.Mast, bool, bool, interface{}, interface{}, interface{}, OnConflictMerged) (bool, error)
var LWW MergeFunc = MergeFunc( func(ctx context.Context, newTree *mast.Mast, added, removed bool, key, addedValue, removedValue interface{}, onConflictMerged OnConflictMerged) (bool, error) { var newValue crdt.Value if !added && !removed { av := addedValue.(crdt.Value) rv := removedValue.(crdt.Value) newValue = *crdt.LastWriteWins(&av, &rv) if onConflictMerged != nil && !av.Tombstoned() && !rv.Tombstoned() && !reflect.DeepEqual(av.Value, rv.Value) { err := onConflictMerged(key, av.Value, rv.Value) if err != nil { return false, fmt.Errorf("OnConflictMerged: %w", err) } } } else if added { return true, nil } else if removed { newValue = removedValue.(crdt.Value) } else { return false, fmt.Errorf("no added/removed value") } err := newTree.Insert(ctx, key, newValue) if err != nil { return false, fmt.Errorf("insert: %w", err) } return true, nil })
type OnConflictMerged ¶
type OnConflictMerged func(key, v1, v2 interface{}) error
type Root ¶
type Root struct { mast.Root Created *time.Time `json:"cr,omitempty"` MergeSources []string `json:"p,omitempty"` MergeMode int `json:"mm,omitempty"` KVVersion int `json:"kv_version,omitempty"` }
Root identifies a tree, a persisted form, that links the mast and ancestors.
Click to show internal directories.
Click to hide internal directories.