Skip to content

Commit

Permalink
Change some names to be the same as App SDK for consistency (#411)
Browse files Browse the repository at this point in the history
  • Loading branch information
hackerwins committed Sep 16, 2022
1 parent 819e46b commit 6ec473d
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 88 deletions.
6 changes: 3 additions & 3 deletions pkg/document/crdt/array.go
Expand Up @@ -88,10 +88,10 @@ func (a *Array) Marshal() string {
return a.elements.Marshal()
}

// AnnotatedString returns a String containing the metadata of the elements
// StructureAsString returns a String containing the metadata of the elements
// for debugging purpose.
func (a *Array) AnnotatedString() string {
return a.elements.AnnotatedString()
func (a *Array) StructureAsString() string {
return a.elements.StructureAsString()
}

// DeepCopy copies itself deeply.
Expand Down
6 changes: 3 additions & 3 deletions pkg/document/crdt/rga_tree_list.go
Expand Up @@ -224,10 +224,10 @@ func (a *RGATreeList) Len() int {
return a.size
}

// AnnotatedString returns a String containing the metadata of the node id
// StructureAsString returns a String containing the metadata of the node id
// for debugging purpose.
func (a *RGATreeList) AnnotatedString() string {
return a.nodeMapByIndex.AnnotatedString()
func (a *RGATreeList) StructureAsString() string {
return a.nodeMapByIndex.StructureAsString()
}

// Delete deletes the node of the given index.
Expand Down
32 changes: 16 additions & 16 deletions pkg/document/crdt/rga_tree_split.go
Expand Up @@ -21,7 +21,7 @@ type RGATreeSplitValue interface {
DeepCopy() RGATreeSplitValue
String() string
Marshal() string
AnnotatedString() string
structureAsString() string
}

// RGATreeSplitNodeID is an ID of RGATreeSplitNode.
Expand Down Expand Up @@ -84,10 +84,10 @@ func (id *RGATreeSplitNodeID) Split(offset int) *RGATreeSplitNodeID {
return NewRGATreeSplitNodeID(id.createdAt, id.offset+offset)
}

// AnnotatedString returns a String containing the metadata of the node id
// StructureAsString returns a String containing the metadata of the node id
// for debugging purpose.
func (id *RGATreeSplitNodeID) AnnotatedString() string {
return fmt.Sprintf("%s:%d", id.createdAt.AnnotatedString(), id.offset)
func (id *RGATreeSplitNodeID) StructureAsString() string {
return fmt.Sprintf("%s:%d", id.createdAt.StructureAsString(), id.offset)
}

func (id *RGATreeSplitNodeID) hasSameCreatedAt(other *RGATreeSplitNodeID) bool {
Expand Down Expand Up @@ -119,10 +119,10 @@ func (pos *RGATreeSplitNodePos) getAbsoluteID() *RGATreeSplitNodeID {
return NewRGATreeSplitNodeID(pos.id.createdAt, pos.id.offset+pos.relativeOffset)
}

// AnnotatedString returns a String containing the metadata of the position
// StructureAsString returns a String containing the metadata of the position
// for debugging purpose.
func (pos *RGATreeSplitNodePos) AnnotatedString() string {
return fmt.Sprintf("%s:%d", pos.id.AnnotatedString(), pos.relativeOffset)
func (pos *RGATreeSplitNodePos) StructureAsString() string {
return fmt.Sprintf("%s:%d", pos.id.StructureAsString(), pos.relativeOffset)
}

// ID returns the ID of this RGATreeSplitNodePos.
Expand Down Expand Up @@ -259,10 +259,10 @@ func (s *RGATreeSplitNode[V]) createdAt() *time.Ticket {
return s.id.createdAt
}

// annotatedString returns a String containing the metadata of the node
// structureAsString returns a String containing the metadata of the node
// for debugging purpose.
func (s *RGATreeSplitNode[V]) annotatedString() string {
return fmt.Sprintf("%s %s", s.id.AnnotatedString(), s.value.AnnotatedString())
func (s *RGATreeSplitNode[V]) structureAsString() string {
return fmt.Sprintf("%s %s", s.id.StructureAsString(), s.value.structureAsString())
}

// Remove removes this node if it created before the time of deletion are
Expand Down Expand Up @@ -348,7 +348,7 @@ func (s *RGATreeSplit[V]) findNodeWithSplit(
func (s *RGATreeSplit[V]) findFloorNodePreferToLeft(id *RGATreeSplitNodeID) *RGATreeSplitNode[V] {
node := s.findFloorNode(id)
if node == nil {
panic("the node of the given id should be found: " + s.AnnotatedString())
panic("the node of the given id should be found: " + s.StructureAsString())
}

if id.offset > 0 && node.id.offset == id.offset {
Expand All @@ -364,7 +364,7 @@ func (s *RGATreeSplit[V]) findFloorNodePreferToLeft(id *RGATreeSplitNodeID) *RGA

func (s *RGATreeSplit[V]) splitNode(node *RGATreeSplitNode[V], offset int) *RGATreeSplitNode[V] {
if offset > node.contentLen() {
panic("offset should be less than or equal to length: " + s.AnnotatedString())
panic("offset should be less than or equal to length: " + s.StructureAsString())
}

if offset == 0 {
Expand Down Expand Up @@ -598,17 +598,17 @@ func (s *RGATreeSplit[V]) nodes() []*RGATreeSplitNode[V] {
return nodes
}

// AnnotatedString returns a String containing the metadata of the nodes
// StructureAsString returns a String containing the metadata of the nodes
// for debugging purpose.
func (s *RGATreeSplit[V]) AnnotatedString() string {
func (s *RGATreeSplit[V]) StructureAsString() string {
builder := strings.Builder{}

node := s.initialHead
for node != nil {
if node.removedAt != nil {
builder.WriteString(fmt.Sprintf("{%s}", node.annotatedString()))
builder.WriteString(fmt.Sprintf("{%s}", node.structureAsString()))
} else {
builder.WriteString(fmt.Sprintf("[%s]", node.annotatedString()))
builder.WriteString(fmt.Sprintf("[%s]", node.structureAsString()))
}
node = node.next
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/document/crdt/rich_text.go
Expand Up @@ -70,9 +70,9 @@ func (t *RichTextValue) Marshal() string {
)
}

// AnnotatedString returns a String containing the metadata of this value
// structureAsString returns a String containing the metadata of this value
// for debugging purpose.
func (t *RichTextValue) AnnotatedString() string {
func (t *RichTextValue) structureAsString() string {
return fmt.Sprintf(
`%s "%s"`,
t.attrs.Marshal(),
Expand Down Expand Up @@ -270,10 +270,10 @@ func (t *RichText) Nodes() []*RGATreeSplitNode[*RichTextValue] {
return t.rgaTreeSplit.nodes()
}

// AnnotatedString returns a String containing the metadata of the text
// StructureAsString returns a String containing the metadata of the text
// for debugging purpose.
func (t *RichText) AnnotatedString() string {
return t.rgaTreeSplit.AnnotatedString()
func (t *RichText) StructureAsString() string {
return t.rgaTreeSplit.StructureAsString()
}

// removedNodesLen returns length of removed nodes
Expand Down
10 changes: 5 additions & 5 deletions pkg/document/crdt/text.go
Expand Up @@ -52,9 +52,9 @@ func (t *TextValue) Marshal() string {
return EscapeString(t.value)
}

// AnnotatedString returns a String containing the metadata of this value
// structureAsString returns a String containing the metadata of this value
// for debugging purpose.
func (t *TextValue) AnnotatedString() string {
func (t *TextValue) structureAsString() string {
return EscapeString(t.value)
}

Expand Down Expand Up @@ -210,10 +210,10 @@ func (t *Text) Nodes() []*RGATreeSplitNode[*TextValue] {
return t.rgaTreeSplit.nodes()
}

// AnnotatedString returns a String containing the metadata of the text
// StructureAsString returns a String containing the metadata of the text
// for debugging purpose.
func (t *Text) AnnotatedString() string {
return t.rgaTreeSplit.AnnotatedString()
func (t *Text) StructureAsString() string {
return t.rgaTreeSplit.StructureAsString()
}

// CheckWeight returns false when there is an incorrect weight node.
Expand Down
38 changes: 19 additions & 19 deletions pkg/document/document_test.go
Expand Up @@ -129,22 +129,22 @@ func TestDocument(t *testing.T) {
root.SetNewArray("k1").AddInteger(1).AddInteger(2).AddInteger(3)
assert.Equal(t, 3, root.GetArray("k1").Len())
assert.Equal(t, `{"k1":[1,2,3]}`, root.Marshal())
assert.Equal(t, "[0,0]0[1,1]1[2,1]2[3,1]3", root.GetArray("k1").AnnotatedString())
assert.Equal(t, "[0,0]0[1,1]1[2,1]2[3,1]3", root.GetArray("k1").StructureAsString())

root.GetArray("k1").Delete(1)
assert.Equal(t, `{"k1":[1,3]}`, root.Marshal())
assert.Equal(t, 2, root.GetArray("k1").Len())
assert.Equal(t, "[0,0]0[1,1]1[2,0]2[1,1]3", root.GetArray("k1").AnnotatedString())
assert.Equal(t, "[0,0]0[1,1]1[2,0]2[1,1]3", root.GetArray("k1").StructureAsString())

root.GetArray("k1").InsertIntegerAfter(0, 2)
assert.Equal(t, `{"k1":[1,2,3]}`, root.Marshal())
assert.Equal(t, 3, root.GetArray("k1").Len())
assert.Equal(t, "[0,0]0[1,1]1[3,1]2[1,0]2[1,1]3", root.GetArray("k1").AnnotatedString())
assert.Equal(t, "[0,0]0[1,1]1[3,1]2[1,0]2[1,1]3", root.GetArray("k1").StructureAsString())

root.GetArray("k1").InsertIntegerAfter(2, 4)
assert.Equal(t, `{"k1":[1,2,3,4]}`, root.Marshal())
assert.Equal(t, 4, root.GetArray("k1").Len())
assert.Equal(t, "[0,0]0[1,1]1[2,1]2[2,0]2[3,1]3[4,1]4", root.GetArray("k1").AnnotatedString())
assert.Equal(t, "[0,0]0[1,1]1[2,1]2[2,0]2[3,1]3[4,1]4", root.GetArray("k1").StructureAsString())

for i := 0; i < root.GetArray("k1").Len(); i++ {
assert.Equal(
Expand Down Expand Up @@ -180,23 +180,23 @@ func TestDocument(t *testing.T) {
text := root.GetText("k1")
assert.Equal(t,
"[0:0:00:0 ][1:2:00:0 A][1:3:00:0 12]{1:2:00:1 BC}[1:2:00:3 D]",
text.AnnotatedString(),
text.StructureAsString(),
)

from, _ := text.CreateRange(0, 0)
assert.Equal(t, "0:0:00:0:0", from.AnnotatedString())
assert.Equal(t, "0:0:00:0:0", from.StructureAsString())

from, _ = text.CreateRange(1, 1)
assert.Equal(t, "1:2:00:0:1", from.AnnotatedString())
assert.Equal(t, "1:2:00:0:1", from.StructureAsString())

from, _ = text.CreateRange(2, 2)
assert.Equal(t, "1:3:00:0:1", from.AnnotatedString())
assert.Equal(t, "1:3:00:0:1", from.StructureAsString())

from, _ = text.CreateRange(3, 3)
assert.Equal(t, "1:3:00:0:2", from.AnnotatedString())
assert.Equal(t, "1:3:00:0:2", from.StructureAsString())

from, _ = text.CreateRange(4, 4)
assert.Equal(t, "1:2:00:3:1", from.AnnotatedString())
assert.Equal(t, "1:2:00:3:1", from.StructureAsString())
return nil
})
assert.NoError(t, err)
Expand Down Expand Up @@ -229,7 +229,7 @@ func TestDocument(t *testing.T) {
assert.Equal(
t,
`[0:0:00:0 {} ""][1:2:00:0 {} "Hello world"][1:1:00:0 {} "\n"]`,
text.AnnotatedString(),
text.StructureAsString(),
)
return nil
})
Expand All @@ -241,7 +241,7 @@ func TestDocument(t *testing.T) {
text.SetStyle(0, 5, map[string]string{"b": "1"})
assert.Equal(t,
`[0:0:00:0 {} ""][1:2:00:0 {"b":"1"} "Hello"][1:2:00:5 {} " world"][1:1:00:0 {} "\n"]`,
text.AnnotatedString(),
text.StructureAsString(),
)
return nil
})
Expand All @@ -258,15 +258,15 @@ func TestDocument(t *testing.T) {
assert.Equal(
t,
`[0:0:00:0 {} ""][1:2:00:0 {"b":"1"} "Hello"][1:2:00:5 {} " world"][1:1:00:0 {} "\n"]`,
text.AnnotatedString(),
text.StructureAsString(),
)

text.SetStyle(3, 5, map[string]string{"i": "1"})
assert.Equal(
t,
`[0:0:00:0 {} ""][1:2:00:0 {"b":"1"} "Hel"][1:2:00:3 {"b":"1","i":"1"} "lo"][1:2:00:5 {} " world"]`+
`[1:1:00:0 {} "\n"]`,
text.AnnotatedString(),
text.StructureAsString(),
)
return nil
})
Expand All @@ -284,7 +284,7 @@ func TestDocument(t *testing.T) {
t,
`[0:0:00:0 {} ""][1:2:00:0 {"b":"1"} "Hel"][1:2:00:3 {"b":"1","i":"1"} "lo"]`+
`[4:1:00:0 {} " Yorkie"]{1:2:00:5 {} " world"}[1:1:00:0 {} "\n"]`,
text.AnnotatedString(),
text.StructureAsString(),
)
return nil
})
Expand All @@ -302,7 +302,7 @@ func TestDocument(t *testing.T) {
t,
`[0:0:00:0 {} ""][1:2:00:0 {"b":"1"} "Hel"][1:2:00:3 {"b":"1","i":"1"} "lo"]`+
`[5:1:00:0 {"list":"true"} "\n"][4:1:00:0 {} " Yorkie"]{1:2:00:5 {} " world"}[1:1:00:0 {} "\n"]`,
text.AnnotatedString(),
text.StructureAsString(),
)
return nil
})
Expand Down Expand Up @@ -465,7 +465,7 @@ func TestDocument(t *testing.T) {
assert.Equal(
t,
`[0:0:00:0 ][1:3:00:0 12]{1:2:00:0 AB}[1:2:00:2 CD]`,
doc.Root().GetText("text").AnnotatedString(),
doc.Root().GetText("text").StructureAsString(),
)

assert.Equal(t, 1, doc.GarbageLen())
Expand All @@ -474,7 +474,7 @@ func TestDocument(t *testing.T) {
assert.Equal(
t,
`[0:0:00:0 ][1:3:00:0 12][1:2:00:2 CD]`,
doc.Root().GetText("text").AnnotatedString(),
doc.Root().GetText("text").StructureAsString(),
)

err = doc.Update(func(root *json.Object) error {
Expand All @@ -485,7 +485,7 @@ func TestDocument(t *testing.T) {
assert.Equal(
t,
`[0:0:00:0 ][1:3:00:0 12]{1:2:00:2 CD}`,
doc.Root().GetText("text").AnnotatedString(),
doc.Root().GetText("text").StructureAsString(),
)
})

Expand Down
4 changes: 2 additions & 2 deletions pkg/document/time/ticket.go
Expand Up @@ -70,9 +70,9 @@ func NewTicket(
}
}

// AnnotatedString returns a string containing the metadata of the ticket
// StructureAsString returns a string containing the metadata of the ticket
// for debugging purpose.
func (t *Ticket) AnnotatedString() string {
func (t *Ticket) StructureAsString() string {
return fmt.Sprintf(
"%d:%d:%s", t.lamport, t.delimiter, t.actorID.String()[22:24],
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/document/time/ticket_test.go
Expand Up @@ -31,7 +31,7 @@ func TestTicket(t *testing.T) {

assert.Equal(t, "0:1:"+ticket.ActorIDHex(), ticket.Key())
assert.Equal(t, "0:1:"+ticket.ActorIDHex()[22:24],
ticket.AnnotatedString())
ticket.StructureAsString())
})

t.Run("ticket comparing test", func(t *testing.T) {
Expand Down
10 changes: 5 additions & 5 deletions pkg/splay/splay.go
Expand Up @@ -220,9 +220,9 @@ func (t *Tree[V]) String() string {
return builder.String()
}

// AnnotatedString returns a string containing the metadata of the Node
// StructureAsString returns a string containing the metadata of the Node
// for debugging purpose.
func (t *Tree[V]) AnnotatedString() string {
func (t *Tree[V]) StructureAsString() string {
var builder strings.Builder

traverseInOrder(t.root, func(node *Node[V]) {
Expand Down Expand Up @@ -286,8 +286,8 @@ func (t *Tree[V]) Delete(node *Node[V]) {
}

if leftTree.root != nil {
maxNode := leftTree.maximum()
leftTree.Splay(maxNode)
rightmost := leftTree.rightmost()
leftTree.Splay(rightmost)
leftTree.root.right = rightTree.root
if rightTree.root != nil {
rightTree.root.parent = leftTree.root
Expand Down Expand Up @@ -379,7 +379,7 @@ func (t *Tree[V]) rotateRight(pivot *Node[V]) {
t.UpdateWeight(pivot)
}

func (t *Tree[V]) maximum() *Node[V] {
func (t *Tree[V]) rightmost() *Node[V] {
node := t.root
for node.right != nil {
node = node.right
Expand Down

0 comments on commit 6ec473d

Please sign in to comment.