change

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2021 License: Apache-2.0 Imports: 5 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// InitialID represents the initial state ID. Usually this is used to
	// represent a state where nothing has been edited.
	InitialID = NewID(0, 0, time.InitialActorID)
)

Functions

This section is empty.

Types

type Change

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

Change represents a unit of modification in the document.

func New

func New(id *ID, message string, operations []operation.Operation) *Change

New creates a new instance of Change.

func (*Change) ClientSeq

func (c *Change) ClientSeq() uint32

ClientSeq returns the clientSeq of this change.

func (*Change) Execute

func (c *Change) Execute(root *json.Root) error

Execute applies this change to the given JSON root.

func (*Change) ID

func (c *Change) ID() *ID

ID returns the ID of this change.

func (*Change) Message

func (c *Change) Message() string

Message returns the message of this change.

func (*Change) Operations

func (c *Change) Operations() []operation.Operation

Operations returns the operations of this change.

func (*Change) ServerSeq

func (c *Change) ServerSeq() uint64

ServerSeq returns the serverSeq of this change.

func (*Change) SetActor

func (c *Change) SetActor(actor *time.ActorID)

SetActor sets the given actor.

func (*Change) SetServerSeq

func (c *Change) SetServerSeq(serverSeq uint64)

SetServerSeq sets the given serverSeq.

type Context

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

Context is used to record the context of modification when editing a document. Each time we add an operation, a new time ticket is issued. Finally, returns a Change after the modification has been completed.

func NewContext

func NewContext(id *ID, message string, root *json.Root) *Context

NewContext creates a new instance of Context.

func (*Context) HasOperations

func (c *Context) HasOperations() bool

HasOperations returns whether this change has operations or not.

func (*Context) ID

func (c *Context) ID() *ID

ID returns ID.

func (*Context) IssueTimeTicket

func (c *Context) IssueTimeTicket() *time.Ticket

IssueTimeTicket creates a time ticket to be used to create a new operation.

func (*Context) Push

func (c *Context) Push(op operation.Operation)

Push pushes a new operation into context queue.

func (*Context) RegisterElement

func (c *Context) RegisterElement(elem json.Element)

RegisterElement registers the given element to the root.

func (*Context) RegisterRemovedElementPair added in v0.1.1

func (c *Context) RegisterRemovedElementPair(parent json.Container, deleted json.Element)

RegisterRemovedElementPair registers the given element pair to hash table.

func (*Context) RegisterTextElementWithGarbage added in v0.1.11

func (c *Context) RegisterTextElementWithGarbage(textType json.TextElement)

RegisterTextElementWithGarbage register the given text element with garbage to hash table.

func (*Context) ToChange

func (c *Context) ToChange() *Change

ToChange creates a new change of this context.

type ID

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

ID is for identifying the Change. This struct is immutable.

func NewID

func NewID(
	clientSeq uint32,
	lamport uint64,
	actorID *time.ActorID,
) *ID

NewID creates a new instance of ID.

func (*ID) Actor

func (id *ID) Actor() *time.ActorID

Actor returns the actor of this ID.

func (*ID) ClientSeq

func (id *ID) ClientSeq() uint32

ClientSeq returns the client sequence of this ID.

func (*ID) Lamport

func (id *ID) Lamport() uint64

Lamport returns the lamport clock of this ID.

func (*ID) NewTimeTicket

func (id *ID) NewTimeTicket(delimiter uint32) *time.Ticket

NewTimeTicket creates a ticket of the given delimiter.

func (*ID) Next

func (id *ID) Next() *ID

Next creates a next ID of this ID.

func (*ID) SetActor

func (id *ID) SetActor(actor *time.ActorID) *ID

SetActor sets actor.

func (*ID) SyncLamport

func (id *ID) SyncLamport(otherLamport uint64) *ID

SyncLamport syncs lamport timestamp with the given ID.

type Pack

type Pack struct {
	// DocumentKey is key of the document.
	DocumentKey *key.Key

	// Checkpoint is used to determine the client received changes.
	Checkpoint *checkpoint.Checkpoint

	// Change represents a unit of modification in the document.
	Changes []*Change

	// Snapshot is a byte array that encode the document.
	Snapshot []byte

	// MinSyncedTicket is the minimum logical time taken by clients who attach the document.
	// It used to collect garbage on the replica on the client.
	MinSyncedTicket *time.Ticket
}

Pack is a unit for delivering changes in a document to the remote.

func NewPack

func NewPack(
	key *key.Key,
	cp *checkpoint.Checkpoint,
	changes []*Change,
	snapshot []byte,
) *Pack

NewPack creates a new instance of Pack.

func (*Pack) ChangesLen added in v0.1.10

func (p *Pack) ChangesLen() int

ChangesLen returns the size of the changes.

func (*Pack) HasChanges

func (p *Pack) HasChanges() bool

HasChanges returns the whether pack has changes or not.

func (*Pack) OperationsLen added in v0.1.10

func (p *Pack) OperationsLen() int

OperationsLen returns the size of the operations.

Jump to

Keyboard shortcuts

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