json

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2021 License: Apache-2.0 Imports: 14 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CounterValueFromBytes

func CounterValueFromBytes(counterType CounterType, value []byte) interface{}

CounterValueFromBytes parses the given bytes into value.

func ValueFromBytes

func ValueFromBytes(valueType ValueType, value []byte) interface{}

ValueFromBytes parses the given bytes into value.

Types

type Array

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

Array represents JSON array data structure including logical clock. Array implements Element interface.

func NewArray

func NewArray(elements *RGATreeList, createdAt *time.Ticket) *Array

NewArray creates a new instance of Array.

func (*Array) Add

func (a *Array) Add(elem Element) *Array

Add adds the given element at the last.

func (*Array) AnnotatedString

func (a *Array) AnnotatedString() string

AnnotatedString returns a String containing the meta data of the elements for debugging purpose.

func (*Array) CreatedAt

func (a *Array) CreatedAt() *time.Ticket

CreatedAt returns the creation time of this array.

func (*Array) DeepCopy

func (a *Array) DeepCopy() Element

DeepCopy copies itself deeply.

func (*Array) Delete

func (a *Array) Delete(idx int, deletedAt *time.Ticket) Element

Delete deletes the element of the given index.

func (*Array) DeleteByCreatedAt

func (a *Array) DeleteByCreatedAt(createdAt *time.Ticket, deletedAt *time.Ticket) Element

DeleteByCreatedAt deletes the given element.

func (*Array) Descendants

func (a *Array) Descendants(callback func(elem Element, parent Container) bool)

Descendants traverse the descendants of this array.

func (*Array) Elements

func (a *Array) Elements() []Element

Elements returns an array of elements contained in this RGATreeList.

func (*Array) FindPrevCreatedAt

func (a *Array) FindPrevCreatedAt(createdAt *time.Ticket) *time.Ticket

FindPrevCreatedAt returns the creation time of the previous element of the given element.

func (*Array) Get

func (a *Array) Get(idx int) Element

Get returns the element of the given index.

func (*Array) InsertAfter

func (a *Array) InsertAfter(prevCreatedAt *time.Ticket, element Element)

InsertAfter inserts the given element after the given previous element.

func (*Array) LastCreatedAt

func (a *Array) LastCreatedAt() *time.Ticket

LastCreatedAt returns the creation time of the last element.

func (*Array) Len

func (a *Array) Len() int

Len returns length of this Array.

func (*Array) Marshal

func (a *Array) Marshal() string

Marshal returns the JSON encoding of this Array.

func (*Array) MoveAfter

func (a *Array) MoveAfter(prevCreatedAt, createdAt, executedAt *time.Ticket)

MoveAfter moves the given `createdAt` element after the `prevCreatedAt` element.

func (*Array) MovedAt

func (a *Array) MovedAt() *time.Ticket

MovedAt returns the move time of this array.

func (*Array) Purge

func (a *Array) Purge(elem Element)

Purge physically purge child element.

func (*Array) RGANodes

func (a *Array) RGANodes() []*RGATreeListNode

RGANodes returns the slices of RGATreeListNode.

func (*Array) Remove

func (a *Array) Remove(removedAt *time.Ticket) bool

Remove removes this array.

func (*Array) RemovedAt

func (a *Array) RemovedAt() *time.Ticket

RemovedAt returns the removal time of this array.

func (*Array) SetMovedAt

func (a *Array) SetMovedAt(movedAt *time.Ticket)

SetMovedAt sets the move time of this array.

func (*Array) SetRemovedAt added in v0.1.6

func (a *Array) SetRemovedAt(removedAt *time.Ticket)

SetRemovedAt sets the removal time of this array.

type Container

type Container interface {
	Element

	Purge(child Element)

	Descendants(callback func(elem Element, parent Container) bool)

	// DeleteByCreatedAt removes the given element from this container.
	DeleteByCreatedAt(createdAt *time.Ticket, deletedAt *time.Ticket) Element
}

Container represents Array or Object.

type Counter

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

Counter represents changeable number data type.

func NewCounter

func NewCounter(value interface{}, createdAt *time.Ticket) *Counter

NewCounter creates a new instance of Counter.

func (*Counter) Bytes

func (p *Counter) Bytes() []byte

Bytes creates an array representing the value.

func (*Counter) CreatedAt

func (p *Counter) CreatedAt() *time.Ticket

CreatedAt returns the creation time.

func (*Counter) DeepCopy

func (p *Counter) DeepCopy() Element

DeepCopy copies itself deeply.

func (*Counter) Increase

func (p *Counter) Increase(v *Primitive) *Counter

Increase increase integer, long or double. If the result of the operation is greater than MaxInt32 or less than MinInt32, Counter's value type can be changed Integer to Long. Because in golang, int can be either int32 or int64. So we need to assert int to int32.

func (*Counter) IsNumericType

func (p *Counter) IsNumericType() bool

IsNumericType checks for numeric types.

func (*Counter) Marshal

func (p *Counter) Marshal() string

Marshal returns the JSON encoding of the value.

func (*Counter) MovedAt

func (p *Counter) MovedAt() *time.Ticket

MovedAt returns the move time of this element.

func (*Counter) Remove

func (p *Counter) Remove(removedAt *time.Ticket) bool

Remove removes this element.

func (*Counter) RemovedAt

func (p *Counter) RemovedAt() *time.Ticket

RemovedAt returns the removal time of this element.

func (*Counter) SetMovedAt

func (p *Counter) SetMovedAt(movedAt *time.Ticket)

SetMovedAt sets the move time of this element.

func (*Counter) SetRemovedAt added in v0.1.6

func (p *Counter) SetRemovedAt(removedAt *time.Ticket)

SetRemovedAt sets the removal time of this array.

func (*Counter) ValueType

func (p *Counter) ValueType() CounterType

ValueType returns the type of the value.

type CounterType

type CounterType int

CounterType represents any type that can be used as a counter.

const (
	IntegerCnt CounterType = iota
	LongCnt
	DoubleCnt
)

The values below are the types that can be used as counters.

type Element

type Element interface {
	// Marshal returns the JSON encoding of this element.
	Marshal() string

	// DeepCopy copies itself deeply.
	DeepCopy() Element

	// CreatedAt returns the creation time of this element.
	CreatedAt() *time.Ticket

	// MovedAt returns the move time of this element.
	MovedAt() *time.Ticket

	// SetMovedAt sets the move time of this element.
	SetMovedAt(*time.Ticket)

	// RemovedAt returns the removal time of this element.
	RemovedAt() *time.Ticket

	// Remove removes this element.
	Remove(*time.Ticket) bool
}

Element represents JSON element.

type ElementPair

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

ElementPair represents pair that has a parent element and child element.

type Object

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

Object represents a JSON object, but unlike regular JSON, it has time tickets which is created by logical clock.

func NewObject

func NewObject(memberNodes *RHTPriorityQueueMap, createdAt *time.Ticket) *Object

NewObject creates a new instance of Object.

func (*Object) CreatedAt

func (o *Object) CreatedAt() *time.Ticket

CreatedAt returns the creation time of this object.

func (*Object) DeepCopy

func (o *Object) DeepCopy() Element

DeepCopy copies itself deeply.

func (*Object) Delete

func (o *Object) Delete(k string, deletedAt *time.Ticket) Element

Delete deletes the element of the given key.

func (*Object) DeleteByCreatedAt

func (o *Object) DeleteByCreatedAt(createdAt *time.Ticket, deletedAt *time.Ticket) Element

DeleteByCreatedAt deletes the element of the given creation time.

func (*Object) Descendants

func (o *Object) Descendants(callback func(elem Element, parent Container) bool)

Descendants traverse the descendants of this object.

func (*Object) Get

func (o *Object) Get(k string) Element

Get returns the value of the given key.

func (*Object) Has

func (o *Object) Has(k string) bool

Has returns whether the element exists of the given key or not.

func (*Object) Marshal

func (o *Object) Marshal() string

Marshal returns the JSON encoding of this object.

func (*Object) Members

func (o *Object) Members() map[string]Element

Members returns the member of this object as a map.

func (*Object) MovedAt

func (o *Object) MovedAt() *time.Ticket

MovedAt returns the move time of this object.

func (*Object) Purge

func (o *Object) Purge(elem Element)

Purge physically purge child element.

func (*Object) RHTNodes

func (o *Object) RHTNodes() []*RHTPQMapNode

RHTNodes returns the RHTPriorityQueueMap nodes.

func (*Object) Remove

func (o *Object) Remove(removedAt *time.Ticket) bool

Remove removes this object.

func (*Object) RemovedAt

func (o *Object) RemovedAt() *time.Ticket

RemovedAt returns the removal time of this object.

func (*Object) Set

func (o *Object) Set(k string, v Element) Element

Set sets the given element of the given key.

func (*Object) SetMovedAt

func (o *Object) SetMovedAt(movedAt *time.Ticket)

SetMovedAt sets the move time of this object.

func (*Object) SetRemovedAt added in v0.1.6

func (o *Object) SetRemovedAt(removedAt *time.Ticket)

SetRemovedAt sets the removal time of this array.

type Primitive

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

Primitive represents JSON primitive data type including logical lock.

func NewPrimitive

func NewPrimitive(value interface{}, createdAt *time.Ticket) *Primitive

NewPrimitive creates a new instance of Primitive.

func (*Primitive) Bytes

func (p *Primitive) Bytes() []byte

Bytes creates an array representing the value.

func (*Primitive) CreatedAt

func (p *Primitive) CreatedAt() *time.Ticket

CreatedAt returns the creation time.

func (*Primitive) DeepCopy

func (p *Primitive) DeepCopy() Element

DeepCopy copies itself deeply.

func (*Primitive) IsNumericType

func (p *Primitive) IsNumericType() bool

IsNumericType checks for numeric types.

func (*Primitive) Marshal

func (p *Primitive) Marshal() string

Marshal returns the JSON encoding of the value.

func (*Primitive) MovedAt

func (p *Primitive) MovedAt() *time.Ticket

MovedAt returns the move time of this element.

func (*Primitive) Remove

func (p *Primitive) Remove(removedAt *time.Ticket) bool

Remove removes this element.

func (*Primitive) RemovedAt

func (p *Primitive) RemovedAt() *time.Ticket

RemovedAt returns the removal time of this element.

func (*Primitive) SetMovedAt

func (p *Primitive) SetMovedAt(movedAt *time.Ticket)

SetMovedAt sets the move time of this element.

func (*Primitive) SetRemovedAt added in v0.1.6

func (p *Primitive) SetRemovedAt(removedAt *time.Ticket)

SetRemovedAt sets the removal time of this element.

func (*Primitive) Value added in v0.1.3

func (p *Primitive) Value() interface{}

Value returns the value of Primitive.

func (*Primitive) ValueType

func (p *Primitive) ValueType() ValueType

ValueType returns the type of the value.

type RGATreeList

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

RGATreeList is a list with improved index-based lookup in RGA. RGA is a linked list that has a logical clock and tombstone. Since RGA is composed as a linked list, index-based element search is slow, O(n). To optimise for fast insertions and removals at any index in the list, RGATreeList has a tree.

func NewRGATreeList

func NewRGATreeList() *RGATreeList

NewRGATreeList creates a new instance of RGATreeList.

func (*RGATreeList) Add

func (a *RGATreeList) Add(elem Element)

Add adds the given element at the last.

func (*RGATreeList) AnnotatedString

func (a *RGATreeList) AnnotatedString() string

AnnotatedString returns a String containing the meta data of the node id for debugging purpose.

func (*RGATreeList) Delete

func (a *RGATreeList) Delete(idx int, deletedAt *time.Ticket) *RGATreeListNode

Delete deletes the node of the given index.

func (*RGATreeList) DeleteByCreatedAt

func (a *RGATreeList) DeleteByCreatedAt(createdAt *time.Ticket, deletedAt *time.Ticket) *RGATreeListNode

DeleteByCreatedAt deletes the given element.

func (*RGATreeList) FindPrevCreatedAt

func (a *RGATreeList) FindPrevCreatedAt(createdAt *time.Ticket) *time.Ticket

FindPrevCreatedAt returns the creation time of the previous element of the given element.

func (*RGATreeList) Get

func (a *RGATreeList) Get(idx int) *RGATreeListNode

Get returns the element of the given index.

func (*RGATreeList) InsertAfter

func (a *RGATreeList) InsertAfter(prevCreatedAt *time.Ticket, elem Element)

InsertAfter inserts the given element after the given previous element.

func (*RGATreeList) LastCreatedAt

func (a *RGATreeList) LastCreatedAt() *time.Ticket

LastCreatedAt returns the creation time of last elements.

func (*RGATreeList) Len

func (a *RGATreeList) Len() int

Len returns length of this RGATreeList.

func (*RGATreeList) Marshal

func (a *RGATreeList) Marshal() string

Marshal returns the JSON encoding of this RGATreeList.

func (*RGATreeList) MoveAfter

func (a *RGATreeList) MoveAfter(prevCreatedAt, createdAt, executedAt *time.Ticket)

MoveAfter moves the given `createdAt` element after the `prevCreatedAt` element.

func (*RGATreeList) Nodes

func (a *RGATreeList) Nodes() []*RGATreeListNode

Nodes returns an array of elements contained in this RGATreeList. TODO: If we encounter performance issues, we need to replace this with other solution.

type RGATreeListNode

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

RGATreeListNode is a node of RGATreeList.

func (*RGATreeListNode) CreatedAt added in v0.1.5

func (n *RGATreeListNode) CreatedAt() *time.Ticket

CreatedAt returns the creation time of this element.

func (*RGATreeListNode) Element

func (n *RGATreeListNode) Element() Element

Element returns the element of this node.

func (*RGATreeListNode) Len

func (n *RGATreeListNode) Len() int

Len returns the length of this node.

func (*RGATreeListNode) PositionedAt added in v0.1.5

func (n *RGATreeListNode) PositionedAt() *time.Ticket

PositionedAt returns the time this element was positioned.

func (*RGATreeListNode) String

func (n *RGATreeListNode) String() string

String returns the string representation of this node.

type RGATreeSplit

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

RGATreeSplit is a block-based list with improved index-based lookup in RGA. The difference from RGATreeList is that it has data on a block basis to reduce the size of CRDT metadata. When an edit occurs on a block, the block is split.

func NewRGATreeSplit

func NewRGATreeSplit(initialHead *RGATreeSplitNode) *RGATreeSplit

NewRGATreeSplit creates a new instance of RGATreeSplit.

func (*RGATreeSplit) AnnotatedString

func (s *RGATreeSplit) AnnotatedString() string

AnnotatedString returns a String containing the meta data of the nodes for debugging purpose.

func (*RGATreeSplit) FindNode

FindNode returns the node of the given ID.

func (*RGATreeSplit) InitialHead

func (s *RGATreeSplit) InitialHead() *RGATreeSplitNode

InitialHead returns the head node of this RGATreeSplit.

func (*RGATreeSplit) InsertAfter

func (s *RGATreeSplit) InsertAfter(prev *RGATreeSplitNode, node *RGATreeSplitNode) *RGATreeSplitNode

InsertAfter inserts the given node after the given previous node.

type RGATreeSplitNode

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

RGATreeSplitNode is a node of RGATreeSplit.

func InitialRichTextNode

func InitialRichTextNode() *RGATreeSplitNode

InitialRichTextNode creates a initial node of RichText. The text is edited as this node is split into multiple nodes.

func InitialTextNode

func InitialTextNode() *RGATreeSplitNode

InitialTextNode creates a initial node of Text. The text is edited as this node is split into multiple nodes.

func NewRGATreeSplitNode

func NewRGATreeSplitNode(id *RGATreeSplitNodeID, value RGATreeSplitValue) *RGATreeSplitNode

NewRGATreeSplitNode creates a new instance of RGATreeSplit.

func (*RGATreeSplitNode) DeepCopy

func (t *RGATreeSplitNode) DeepCopy() *RGATreeSplitNode

DeepCopy returns a new instance of this RGATreeSplitNode without structural info.

func (*RGATreeSplitNode) ID

ID returns the ID of this RGATreeSplitNode.

func (*RGATreeSplitNode) InsPrevID

func (t *RGATreeSplitNode) InsPrevID() *RGATreeSplitNodeID

InsPrevID returns previous node ID at the time of this node insertion.

func (*RGATreeSplitNode) Len

func (t *RGATreeSplitNode) Len() int

Len returns the length of this node.

func (*RGATreeSplitNode) Remove

func (t *RGATreeSplitNode) Remove(removedAt *time.Ticket, latestCreatedAt *time.Ticket) bool

Remove removes this node if it created before the time of deletion are deleted. It only marks the deleted time (tombstone).

func (*RGATreeSplitNode) RemovedAt

func (t *RGATreeSplitNode) RemovedAt() *time.Ticket

RemovedAt return the remove time of this node.

func (*RGATreeSplitNode) SetInsPrev

func (t *RGATreeSplitNode) SetInsPrev(node *RGATreeSplitNode)

SetInsPrev sets previous node of this node insertion.

func (*RGATreeSplitNode) String

func (t *RGATreeSplitNode) String() string

String returns the string representation of this node.

func (*RGATreeSplitNode) Value

Value returns the value of this node.

type RGATreeSplitNodeID

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

RGATreeSplitNodeID is an ID of RGATreeSplitNode.

func NewRGATreeSplitNodeID

func NewRGATreeSplitNodeID(createdAt *time.Ticket, offset int) *RGATreeSplitNodeID

NewRGATreeSplitNodeID creates a new instance of RGATreeSplitNodeID.

func (*RGATreeSplitNodeID) AnnotatedString

func (t *RGATreeSplitNodeID) AnnotatedString() string

AnnotatedString returns a String containing the meta data of the node id for debugging purpose.

func (*RGATreeSplitNodeID) Compare

func (t *RGATreeSplitNodeID) Compare(other llrb.Key) int

Compare returns an integer comparing two ID. The result will be 0 if id==other, -1 if id < other, and +1 if id > other. If the receiver or argument is nil, it would panic at runtime.

func (*RGATreeSplitNodeID) CreatedAt

func (t *RGATreeSplitNodeID) CreatedAt() *time.Ticket

CreatedAt returns the creation time of this ID.

func (*RGATreeSplitNodeID) Equal

func (t *RGATreeSplitNodeID) Equal(other llrb.Key) bool

Equal returns whether given ID equals to this ID or not.

func (*RGATreeSplitNodeID) Offset

func (t *RGATreeSplitNodeID) Offset() int

Offset returns the offset of this ID.

func (*RGATreeSplitNodeID) Split

func (t *RGATreeSplitNodeID) Split(offset int) *RGATreeSplitNodeID

Split creates a new ID with an offset from this ID.

type RGATreeSplitNodePos

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

RGATreeSplitNodePos is the position of the text inside the node.

func NewRGATreeSplitNodePos

func NewRGATreeSplitNodePos(id *RGATreeSplitNodeID, offset int) *RGATreeSplitNodePos

NewRGATreeSplitNodePos creates a new instance of RGATreeSplitNodePos.

func (*RGATreeSplitNodePos) AnnotatedString

func (pos *RGATreeSplitNodePos) AnnotatedString() string

AnnotatedString returns a String containing the meta data of the position for debugging purpose.

func (*RGATreeSplitNodePos) Compare added in v0.1.1

func (pos *RGATreeSplitNodePos) Compare(other *RGATreeSplitNodePos) int

Compare compares the offset between RGATreeSplitNodePos.

func (*RGATreeSplitNodePos) ID

ID returns the ID of this RGATreeSplitNodePos.

func (*RGATreeSplitNodePos) RelativeOffset

func (pos *RGATreeSplitNodePos) RelativeOffset() int

RelativeOffset returns the relative offset of this RGATreeSplitNodePos.

type RGATreeSplitValue

type RGATreeSplitValue interface {
	Split(offset int) RGATreeSplitValue
	Len() int
	DeepCopy() RGATreeSplitValue
	String() string
	AnnotatedString() string
}

RGATreeSplitValue is a value of RGATreeSplitNode.

type RHT

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

RHT is a hashtable with logical clock(Replicated hashtable). For more details about RHT: http://csl.skku.edu/papers/jpdc11.pdf

func NewRHT

func NewRHT() *RHT

NewRHT creates a new instance of RHT.

func (*RHT) DeepCopy

func (rht *RHT) DeepCopy() *RHT

DeepCopy copies itself deeply.

func (*RHT) Elements

func (rht *RHT) Elements() map[string]string

Elements returns a map of elements because the map easy to use for loop. TODO: If we encounter performance issues, we need to replace this with other solution.

func (*RHT) Get

func (rht *RHT) Get(key string) string

Get returns the value of the given key.

func (*RHT) Has

func (rht *RHT) Has(key string) bool

Has returns whether the element exists of the given key or not.

func (*RHT) Marshal

func (rht *RHT) Marshal() string

Marshal returns the JSON encoding of this hashtable.

func (*RHT) Nodes

func (rht *RHT) Nodes() []*RHTNode

Nodes returns a map of elements because the map easy to use for loop. TODO: If we encounter performance issues, we need to replace this with other solution.

func (*RHT) Remove

func (rht *RHT) Remove(k string, executedAt *time.Ticket) string

Remove removes the Element of the given key.

func (*RHT) RemoveByCreatedAt

func (rht *RHT) RemoveByCreatedAt(createdAt *time.Ticket, removedAt *time.Ticket) string

RemoveByCreatedAt removes the Element of the given creation time.

func (*RHT) Set

func (rht *RHT) Set(k, v string, executedAt *time.Ticket)

Set sets the value of the given key.

type RHTNode

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

RHTNode is a node of RHT(Replicated Hashtable).

func (*RHTNode) Key

func (n *RHTNode) Key() string

Key returns the key of this node.

func (*RHTNode) Remove

func (n *RHTNode) Remove(removedAt *time.Ticket)

Remove removes this node. It only marks the deleted time (tombstone).

func (*RHTNode) RemovedAt

func (n *RHTNode) RemovedAt() *time.Ticket

RemovedAt returns the deletion time of this node.

func (*RHTNode) UpdatedAt

func (n *RHTNode) UpdatedAt() *time.Ticket

UpdatedAt returns the last update time.

func (*RHTNode) Value

func (n *RHTNode) Value() string

Value returns the value of this node.

type RHTPQMapNode

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

RHTPQMapNode is a node of RHTPQMap.

func (*RHTPQMapNode) Element

func (n *RHTPQMapNode) Element() Element

Element returns the element of this node.

func (*RHTPQMapNode) Key

func (n *RHTPQMapNode) Key() string

Key returns the key of this node.

func (*RHTPQMapNode) Less

func (n *RHTPQMapNode) Less(other pq.Value) bool

Less is the implementation of the PriorityQueue Value interface. In RHTPQMap, elements inserted later must be exposed above.

func (*RHTPQMapNode) Remove

func (n *RHTPQMapNode) Remove(removedAt *time.Ticket) bool

Remove removes this node. It only marks the deleted time (tombstone).

type RHTPriorityQueueMap

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

RHTPriorityQueueMap is a hashtable with logical clock(Replicated hashtable). The difference from RHT is that it keeps multiple values in one key. Using Max Heap, the recently inserted value from the logical clock is returned to the outside.

func NewRHTPriorityQueueMap

func NewRHTPriorityQueueMap() *RHTPriorityQueueMap

NewRHTPriorityQueueMap creates a new instance of RHTPriorityQueueMap.

func (*RHTPriorityQueueMap) Delete

func (rht *RHTPriorityQueueMap) Delete(k string, deletedAt *time.Ticket) Element

Delete deletes the Element of the given key.

func (*RHTPriorityQueueMap) DeleteByCreatedAt

func (rht *RHTPriorityQueueMap) DeleteByCreatedAt(createdAt *time.Ticket, deletedAt *time.Ticket) Element

DeleteByCreatedAt deletes the Element of the given creation time.

func (*RHTPriorityQueueMap) Elements

func (rht *RHTPriorityQueueMap) Elements() map[string]Element

Elements returns a map of elements because the map easy to use for loop. TODO: If we encounter performance issues, we need to replace this with other solution.

func (*RHTPriorityQueueMap) Get

func (rht *RHTPriorityQueueMap) Get(key string) Element

Get returns the value of the given key.

func (*RHTPriorityQueueMap) Has

func (rht *RHTPriorityQueueMap) Has(key string) bool

Has returns whether the element exists of the given key or not.

func (*RHTPriorityQueueMap) Marshal

func (rht *RHTPriorityQueueMap) Marshal() string

Marshal returns the JSON encoding of this map.

func (*RHTPriorityQueueMap) Nodes

func (rht *RHTPriorityQueueMap) Nodes() []*RHTPQMapNode

Nodes returns a map of elements because the map easy to use for loop. TODO: If we encounter performance issues, we need to replace this with other solution.

func (*RHTPriorityQueueMap) Set

func (rht *RHTPriorityQueueMap) Set(k string, v Element) Element

Set sets the value of the given key. If there is an existing value, it is removed.

func (*RHTPriorityQueueMap) SetInternal added in v0.1.6

func (rht *RHTPriorityQueueMap) SetInternal(k string, v Element)

SetInternal sets the value of the given key.

type RichText

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

RichText is an extended data type for the contents of a text editor.

func NewInitialRichText

func NewInitialRichText(elements *RGATreeSplit, createdAt *time.Ticket) *RichText

NewInitialRichText creates a new instance of RichText.

func NewRichText

func NewRichText(elements *RGATreeSplit, createdAt *time.Ticket) *RichText

NewRichText creates a new instance of RichText.

func (*RichText) AnnotatedString

func (t *RichText) AnnotatedString() string

AnnotatedString returns a String containing the meta data of the text for debugging purpose.

func (*RichText) CreateRange

func (t *RichText) CreateRange(from, to int) (*RGATreeSplitNodePos, *RGATreeSplitNodePos)

CreateRange returns pair of RGATreeSplitNodePos of the given integer offsets.

func (*RichText) CreatedAt

func (t *RichText) CreatedAt() *time.Ticket

CreatedAt returns the creation time of this Text.

func (*RichText) DeepCopy

func (t *RichText) DeepCopy() Element

DeepCopy copies itself deeply.

func (*RichText) Edit

func (t *RichText) Edit(
	from,
	to *RGATreeSplitNodePos,
	latestCreatedAtMapByActor map[string]*time.Ticket,
	content string,
	attributes map[string]string,
	executedAt *time.Ticket,
) (*RGATreeSplitNodePos, map[string]*time.Ticket)

Edit edits the given range with the given content and attributes.

func (*RichText) Marshal

func (t *RichText) Marshal() string

Marshal returns the JSON encoding of this rich text.

func (*RichText) MovedAt

func (t *RichText) MovedAt() *time.Ticket

MovedAt returns the move time of this Text.

func (*RichText) Nodes

func (t *RichText) Nodes() []*RGATreeSplitNode

Nodes returns the internal nodes of this rich text.

func (*RichText) Remove

func (t *RichText) Remove(removedAt *time.Ticket) bool

Remove removes this Text.

func (*RichText) RemovedAt

func (t *RichText) RemovedAt() *time.Ticket

RemovedAt returns the removal time of this Text.

func (*RichText) Select

func (t *RichText) Select(
	from *RGATreeSplitNodePos,
	to *RGATreeSplitNodePos,
	executedAt *time.Ticket,
)

Select stores that the given range has been selected.

func (*RichText) SetMovedAt

func (t *RichText) SetMovedAt(movedAt *time.Ticket)

SetMovedAt sets the move time of this Text.

func (*RichText) SetRemovedAt added in v0.1.6

func (t *RichText) SetRemovedAt(removedAt *time.Ticket)

SetRemovedAt sets the removal time of this array.

func (*RichText) SetStyle

func (t *RichText) SetStyle(
	from,
	to *RGATreeSplitNodePos,
	attributes map[string]string,
	executedAt *time.Ticket,
)

SetStyle applies the style of the given range.

type RichTextValue

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

RichTextValue is a value of RichText which has a attributes that expresses the text style.

func NewRichTextValue

func NewRichTextValue(attrs *RHT, value string) *RichTextValue

NewRichTextValue creates a value of RichText.

func (*RichTextValue) AnnotatedString

func (t *RichTextValue) AnnotatedString() string

AnnotatedString returns a String containing the meta data of this value for debugging purpose.

func (*RichTextValue) Attrs

func (t *RichTextValue) Attrs() *RHT

Attrs returns the attributes of this value.

func (*RichTextValue) DeepCopy

func (t *RichTextValue) DeepCopy() RGATreeSplitValue

DeepCopy copies itself deeply.

func (*RichTextValue) Len

func (t *RichTextValue) Len() int

Len returns the length of this value. It is calculated in UTF-16 code units.

func (*RichTextValue) Split

func (t *RichTextValue) Split(offset int) RGATreeSplitValue

Split splits this value by the given offset.

func (*RichTextValue) String

func (t *RichTextValue) String() string

String returns the string representation of this value.

func (*RichTextValue) Value

func (t *RichTextValue) Value() string

Value returns the value of this rich text value.

type Root

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

Root is a structure represents the root of JSON. It has a hash table of all JSON elements to find a specific element when applying remote changes received from agent.

Every element has a unique time ticket at creation, which allows us to find a particular element.

func NewRoot

func NewRoot(root *Object) *Root

NewRoot creates a new instance of Root.

func (*Root) DeepCopy

func (r *Root) DeepCopy() *Root

DeepCopy copies itself deeply.

func (*Root) DeregisterElement

func (r *Root) DeregisterElement(elem Element)

DeregisterElement deregister the given element from hash tables.

func (*Root) FindByCreatedAt

func (r *Root) FindByCreatedAt(createdAt *time.Ticket) Element

FindByCreatedAt returns the element of given creation time.

func (*Root) GarbageCollect

func (r *Root) GarbageCollect(ticket *time.Ticket) int

GarbageCollect purge elements that were removed before the given time.

func (*Root) GarbageLen

func (r *Root) GarbageLen() int

GarbageLen returns the count of removed elements.

func (*Root) Object

func (r *Root) Object() *Object

Object returns the root object of the JSON.

func (*Root) RegisterElement

func (r *Root) RegisterElement(elem Element)

RegisterElement registers the given element to hash table.

func (*Root) RegisterRemovedElementPair

func (r *Root) RegisterRemovedElementPair(parent Container, elem Element)

RegisterRemovedElementPair register the given element pair to hash table.

func (*Root) RegisterRemovedNodeTextElement added in v0.1.1

func (r *Root) RegisterRemovedNodeTextElement(textType TextElement)

RegisterRemovedNodeTextElement register the given text element to hash table.

type Selection

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

Selection represents the selection of text range in the editor.

type Text

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

Text is an extended data type for the contents of a text editor.

func NewText

func NewText(elements *RGATreeSplit, createdAt *time.Ticket) *Text

NewText creates a new instance of Text.

func (*Text) AnnotatedString

func (t *Text) AnnotatedString() string

AnnotatedString returns a String containing the meta data of the text for debugging purpose.

func (*Text) CreateRange

func (t *Text) CreateRange(from, to int) (*RGATreeSplitNodePos, *RGATreeSplitNodePos)

CreateRange returns pair of RGATreeSplitNodePos of the given integer offsets.

func (*Text) CreatedAt

func (t *Text) CreatedAt() *time.Ticket

CreatedAt returns the creation time of this Text.

func (*Text) DeepCopy

func (t *Text) DeepCopy() Element

DeepCopy copies itself deeply.

func (*Text) Edit

func (t *Text) Edit(
	from,
	to *RGATreeSplitNodePos,
	latestCreatedAtMapByActor map[string]*time.Ticket,
	content string,
	executedAt *time.Ticket,
) (*RGATreeSplitNodePos, map[string]*time.Ticket)

Edit edits the given range with the given content.

func (*Text) Marshal

func (t *Text) Marshal() string

Marshal returns the JSON encoding of this text.

func (*Text) MovedAt

func (t *Text) MovedAt() *time.Ticket

MovedAt returns the move time of this Text.

func (*Text) Nodes

func (t *Text) Nodes() []*RGATreeSplitNode

Nodes returns the internal nodes of this text.

func (*Text) Remove

func (t *Text) Remove(removedAt *time.Ticket) bool

Remove removes this Text.

func (*Text) RemovedAt

func (t *Text) RemovedAt() *time.Ticket

RemovedAt returns the removal time of this Text.

func (*Text) Select

func (t *Text) Select(
	from *RGATreeSplitNodePos,
	to *RGATreeSplitNodePos,
	executedAt *time.Ticket,
)

Select stores that the given range has been selected.

func (*Text) SetMovedAt

func (t *Text) SetMovedAt(movedAt *time.Ticket)

SetMovedAt sets the move time of this Text.

func (*Text) SetRemovedAt added in v0.1.6

func (t *Text) SetRemovedAt(removedAt *time.Ticket)

SetRemovedAt sets the removal time of this array.

type TextElement added in v0.1.1

type TextElement interface {
	Element
	// contains filtered or unexported methods
}

TextElement represents Text or RichText.

type TextValue

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

TextValue is a value of Text.

func NewTextValue

func NewTextValue(value string) *TextValue

NewTextValue creates a value of Text.

func (*TextValue) AnnotatedString

func (t *TextValue) AnnotatedString() string

AnnotatedString returns a String containing the meta data of this value for debugging purpose.

func (*TextValue) DeepCopy

func (t *TextValue) DeepCopy() RGATreeSplitValue

DeepCopy copies itself deeply.

func (*TextValue) Len

func (t *TextValue) Len() int

Len returns the length of this value. It is calculated in UTF-16 code units.

func (*TextValue) Split

func (t *TextValue) Split(offset int) RGATreeSplitValue

Split splits this value by the given offset.

func (*TextValue) String

func (t *TextValue) String() string

String returns the string representation of this value.

type ValueType

type ValueType int

ValueType represents the type of Primitive value.

const (
	Null ValueType = iota
	Boolean
	Integer
	Long
	Double
	String
	Bytes
	Date
)

The types of values that Primitive can have are as follows.

Jump to

Keyboard shortcuts

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