ot¶
Index¶
- func Apply(doc string, op Operation) (string, error)
- type Component
- func (c Component) IsDelete() bool
- func (c Component) IsInsert() bool
- func (c Component) IsRetain() bool
- type Document
- func NewDocument(content string) *Document
- func (d *Document) Apply(op Operation) error
- type Engine
- type JupiterEngine
- func (e *JupiterEngine) TransformIncoming(op Operation, revision int, history []Operation) (Operation, error)
- type Operation
- func NewDelete(pos, count, docLen int) Operation
- func NewInsert(pos int, text string, docLen int) Operation
- func Transform(a, b Operation) (aPrime, bPrime Operation, err error)
- func (op Operation) BaseLen() int
- func (op Operation) IsNoop() bool
- func (op Operation) TargetLen() int
func Apply¶
Apply applies the operation to a document string.
type Component¶
Component is a single step in an OT operation. Exactly one field should be set.
type Component struct {
Retain int `json:"retain,omitempty"` // keep N chars unchanged
Insert string `json:"insert,omitempty"` // insert text at cursor
Delete int `json:"delete,omitempty"` // remove N chars at cursor
}
func (Component) IsDelete¶
func (Component) IsInsert¶
func (Component) IsRetain¶
type Document¶
Document represents a collaborative document with its full operation history.
func NewDocument¶
NewDocument creates a new document with the given initial content.
func (*Document) Apply¶
Apply applies an operation to the document, appending it to history.
type Engine¶
Engine abstracts the OT collaboration algorithm. Different algorithms (Jupiter, Wave, etc.) implement this interface.
type Engine interface {
// TransformIncoming transforms a client operation (created at the given
// revision) against all operations in the history since that revision.
// Returns the operation transformed to apply at the current server state.
TransformIncoming(op Operation, revision int, history []Operation) (Operation, error)
}
type JupiterEngine¶
JupiterEngine implements the Jupiter OT algorithm. It sequentially transforms the incoming operation against each server operation the client hasn't seen.
func (*JupiterEngine) TransformIncoming¶
func (e *JupiterEngine) TransformIncoming(op Operation, revision int, history []Operation) (Operation, error)
type Operation¶
Operation is a sequence of components that transforms a document. Components are applied left-to-right, advancing a cursor through the input.
func NewDelete¶
NewDelete creates an operation that deletes count chars at pos in a document of docLen.
func NewInsert¶
NewInsert creates an operation that inserts text at pos in a document of docLen.
func Transform¶
Transform takes two concurrent operations a and b (both applied to the same document state) and returns aPrime and bPrime such that:
func (Operation) BaseLen¶
BaseLen returns the expected input document length.
func (Operation) IsNoop¶
IsNoop returns true if the operation makes no changes.
func (Operation) TargetLen¶
TargetLen returns the document length after the operation is applied.
Generated by gomarkdoc