ot

package
v0.0.0-...-c85e1c3 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2017 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Apply

func Apply(o Op, t *Tree) error

func AsRunes

func AsRunes(s string) []rune

func AsString

func AsString(rs []rune) string

func CloneRunes

func CloneRunes(body []rune) []rune

func RandIntn

func RandIntn(n int) int

func Transform

func Transform(as, bs Ops) (Ops, Ops, error)

Types

type Controller

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

func NewController

func NewController(sender Sender, receiver Receiver) *Controller

func (*Controller) IsSynchronized

func (c *Controller) IsSynchronized() bool

func (*Controller) OnClientWrite

func (c *Controller) OnClientWrite(ops Ops)

func (*Controller) OnServerAck

func (c *Controller) OnServerAck(rev int, ops Ops)

func (*Controller) OnServerWrite

func (c *Controller) OnServerWrite(rev int, ops Ops)

func (*Controller) ServerRev

func (c *Controller) ServerRev() int

func (*Controller) String

func (c *Controller) String() string

type Doc

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

func NewDoc

func NewDoc() *Doc

func (*Doc) Apply

func (d *Doc) Apply(os Ops) error

func (*Doc) GetRandomOps

func (d *Doc) GetRandomOps(numChars int) Ops

func (*Doc) Len

func (d *Doc) Len() int

func (*Doc) String

func (d *Doc) String() string

type Op

type Op struct {
	// Tag indicates what kind of Op we have
	Tag OpTag

	// Len is either delete-len (if negative) or retain-len (if positive)
	Size int

	// Body is the tree to be inserted
	Body Tree

	// Kids are the child-ops for parent With operations
	Kids Ops
}

func D

func D(n int) Op

D creates a delete op

func Ic

func Ic(r rune) Op

Ic converts r into a single leaf insertion op

func It

func It(t Tree) Op

It creates an insertion op based on t

func R

func R(n int) Op

R creates a retain op

func W

func W(kids Ops) Op

W returns a With op wrapping kids

func Z

func Z() Op

Z returns a nil op

func (Op) Clone

func (o Op) Clone() Op

func (*Op) IsDelete

func (o *Op) IsDelete() bool

func (*Op) IsInsert

func (o *Op) IsInsert() bool

func (*Op) IsInsertBranch

func (o *Op) IsInsertBranch() bool

func (*Op) IsInsertLeaf

func (o *Op) IsInsertLeaf() bool

func (*Op) IsRetain

func (o *Op) IsRetain() bool

func (*Op) IsWith

func (o *Op) IsWith() bool

func (*Op) IsZero

func (o *Op) IsZero() bool

func (*Op) Len

func (o *Op) Len() int

Len returns the tree-len of o; i.e., the number of tree nodes affected by o.

func (Op) SplitAt

func (o Op) SplitAt(n int) (Op, Op, error)

func (*Op) String

func (o *Op) String() string

type OpTag

type OpTag int
const (
	O_NIL OpTag = iota
	O_INSERT
	O_RETAIN
	O_DELETE
	O_WITH
)

type Ops

type Ops []Op

func C

func C(os ...Ops) Ops

C concatenates multiple Ops slices

func Compose

func Compose(as, bs Ops) (Ops, error)

func ComposeAll

func ComposeAll(all []Ops) (Ops, error)

func Ds

func Ds(n int) Ops

Ds creates an op slice containing a single delete op

func Ir

func Ir(rs []rune) Ops

Ir converts rs into a slice of rune leaf insertion ops

func Is

func Is(s string) Ops

Is converts s into a slice of rune leaf insertion ops

func NewDelete

func NewDelete(docLen int, pos int, length int) Ops

func NewInsert

func NewInsert(docLen int, pos int, s string) Ops

func Normalize

func Normalize(os Ops) (Ops, error)

func Rs

func Rs(n int) Ops

Rs creates an op slice containing a single retain op

func Ws

func Ws(kids Ops) Ops

Ws returns an op slice containing a single With op wrapping kids

func Zs

func Zs() Ops

Zs returns an op slice wrapping a single nil op

func (Ops) Clone

func (os Ops) Clone() Ops

func (*Ops) Delete

func (os *Ops) Delete(size int)

func (Ops) Empty

func (os Ops) Empty() bool

func (Ops) First

func (os Ops) First() *Op

func (*Ops) Insert

func (os *Ops) Insert(t Tree)

func (Ops) Last

func (os Ops) Last() *Op

func (Ops) Rest

func (os Ops) Rest() Ops

func (*Ops) Retain

func (os *Ops) Retain(size int)

func (Ops) SplitAt

func (os Ops) SplitAt(n int) (Ops, Ops, error)

func (Ops) String

func (os Ops) String() string

func (*Ops) With

func (os *Ops) With(kids Ops)

type Receiver

type Receiver interface {
	Recv(ops Ops)
}

type Sender

type Sender interface {
	Send(rev int, hash string, ops Ops)
}

type State

type State int
const (
	CS_SYNCED State = iota
	CS_WAIT_ONE
	CS_WAIT_MANY
)

type Tree

type Tree struct {
	Tag  TreeTag
	Leaf rune
	Kids Trees
}

func AsRuneTree

func AsRuneTree(s string) Tree

func Branch

func Branch(kids Trees) Tree

func Leaf

func Leaf(leaf rune) Tree

func Zt

func Zt() Tree

func (Tree) Clone

func (t Tree) Clone() Tree

func (*Tree) IsBranch

func (t *Tree) IsBranch() bool

func (*Tree) IsLeaf

func (t *Tree) IsLeaf() bool

func (*Tree) IsZero

func (t *Tree) IsZero() bool

func (Tree) Len

func (t Tree) Len() int

func (Tree) SplitAt

func (t Tree) SplitAt(n int) (Tree, Tree, error)

func (*Tree) String

func (t *Tree) String() string

type TreeTag

type TreeTag int
const (
	T_NIL TreeTag = iota
	T_LEAF
	T_BRANCH
)

type Trees

type Trees []Tree

func (Trees) Clone

func (ts Trees) Clone() Trees

func (Trees) Empty

func (ts Trees) Empty() bool

func (Trees) First

func (ts Trees) First() *Tree

func (Trees) Last

func (ts Trees) Last() *Tree

func (Trees) Len

func (ts Trees) Len() int

func (Trees) Rest

func (ts Trees) Rest() Trees

func (Trees) SplitAt

func (ts Trees) SplitAt(n int) (Trees, Trees, error)

func (Trees) String

func (ts Trees) String() string

type Zipper

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

func NewZipper

func NewZipper(root *Tree, index int, depth int) *Zipper

func (*Zipper) CanSkip

func (z *Zipper) CanSkip(n int) bool

func (*Zipper) Current

func (z *Zipper) Current() *Tree

func (*Zipper) Delete

func (z *Zipper) Delete(n int)

func (*Zipper) Depth

func (z *Zipper) Depth() int

func (*Zipper) Down

func (z *Zipper) Down()

func (*Zipper) HasDown

func (z *Zipper) HasDown() bool

func (*Zipper) Index

func (z *Zipper) Index() int

func (*Zipper) IndexP

func (z *Zipper) IndexP() *int

func (*Zipper) Insert

func (z *Zipper) Insert(t Tree)

Insert inserts t to the right of the current caret but does not move the caret.

func (*Zipper) Parent

func (z *Zipper) Parent() *Tree

func (*Zipper) Retain

func (z *Zipper) Retain(n int)

func (*Zipper) Skip

func (z *Zipper) Skip(n int)

func (*Zipper) Up

func (z *Zipper) Up()

Notes

Bugs

  • should With() fold into previous With ops?

  • on a newly created zipper to a Branch(nil), tz.Current is nil because our zipper is an insertion-point, at index 0, to the left of cell #0 in t.Kids (bug?).

    However, as we advance down into t, we will create new zippers each time we descend (bug?). Therefore, for the purposes of applying a top-level With-op, we want to recurse on tz.Parent()

    However, assuming we're already in the middle of processing, current will correctly point to the branch to be modified.

    (Argh!)

  • how to shorten With ops?

  • needed for op.IsZero(), but is it correct?

Jump to

Keyboard shortcuts

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