Skip to content

Commit

Permalink
Add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
hackerwins committed Dec 19, 2024
1 parent 6f98675 commit e37c3ea
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
4 changes: 3 additions & 1 deletion pkg/document/crdt/rga_tree_split.go
Original file line number Diff line number Diff line change
Expand Up @@ -548,16 +548,18 @@ func (s *RGATreeSplit[V]) deleteNodes(
var maxCreatedAt *time.Ticket
var clientLamportAtChange int64
if isVersionVectorEmpty && isMaxCreatedAtMapByActorEmpty {
// Local edit - use version vector comparison
// Case 1: local editing from json package
clientLamportAtChange = time.MaxLamport
} else if !isVersionVectorEmpty {
// Case 2: from operation with version vector(After v0.5.7)
lamport, ok := versionVector.Get(actorID)
if ok {
clientLamportAtChange = lamport
} else {
clientLamportAtChange = 0
}
} else {
// Case 3: from operation without version vector(Before v0.5.6)
createdAt, ok := maxCreatedAtMapByActor[actorIDHex]
if ok {
maxCreatedAt = createdAt
Expand Down
4 changes: 3 additions & 1 deletion pkg/document/crdt/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,16 +324,18 @@ func (t *Text) Style(
var maxCreatedAt *time.Ticket
var clientLamportAtChange int64
if isVersionVectorEmpty && isMaxCreatedAtMapByActorEmpty {
// Local edit - use version vector comparison
// Case 1: local editing from json package
clientLamportAtChange = time.MaxLamport
} else if !isVersionVectorEmpty {
// Case 2: from operation with version vector(After v0.5.7)
lamport, ok := versionVector.Get(actorID)
if ok {
clientLamportAtChange = lamport
} else {
clientLamportAtChange = 0
}
} else {
// Case 3: from operation without version vector(Before v0.5.6)
createdAt, ok := maxCreatedAtMapByActor[actorIDHex]
if ok {
maxCreatedAt = createdAt
Expand Down
13 changes: 10 additions & 3 deletions pkg/document/crdt/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -872,17 +872,20 @@ func (t *Tree) collectBetween(

var maxCreatedAt *time.Ticket
var clientLamportAtChange int64

if isVersionVectorEmpty && isMaxCreatedAtMapByActorEmpty {
// Local edit - use version vector comparison
// Case 1: local editing from json package
clientLamportAtChange = time.MaxLamport
} else if !isVersionVectorEmpty {
// Case 2: from operation with version vector(After v0.5.7)
lamport, ok := versionVector.Get(actorID)
if ok {
clientLamportAtChange = lamport
} else {
clientLamportAtChange = 0
}
} else {
// Case 3: from operation without version vector(Before v0.5.6)
createdAt, ok := maxCreatedAtMapByActor[actorIDHex]
if ok {
maxCreatedAt = createdAt
Expand Down Expand Up @@ -1016,16 +1019,18 @@ func (t *Tree) Style(
var maxCreatedAt *time.Ticket
var clientLamportAtChange int64
if isVersionVectorEmpty && isMaxCreatedAtMapByActorEmpty {
// Local edit - use version vector comparison
// Case 1: local editing from json package
clientLamportAtChange = time.MaxLamport
} else if !isVersionVectorEmpty {
// Case 2: from operation with version vector(After v0.5.7)
lamport, ok := versionVector.Get(actorID)
if ok {
clientLamportAtChange = lamport
} else {
clientLamportAtChange = 0
}
} else {
// Case 3: from operation without version vector(Before v0.5.6)
createdAt, ok := maxCreatedAtMapByActor[actorIDHex]
if ok {
maxCreatedAt = createdAt
Expand Down Expand Up @@ -1088,16 +1093,18 @@ func (t *Tree) RemoveStyle(
var maxCreatedAt *time.Ticket
var clientLamportAtChange int64
if isVersionVectorEmpty && isMaxCreatedAtMapByActorEmpty {
// Local edit - use version vector comparison
// Case 1: local editing from json package
clientLamportAtChange = time.MaxLamport
} else if !isVersionVectorEmpty {
// Case 2: from operation with version vector(After v0.5.7)
lamport, ok := versionVector.Get(actorID)
if ok {
clientLamportAtChange = lamport
} else {
clientLamportAtChange = 0
}
} else {
// Case 3: from operation without version vector(Before v0.5.6)
createdAt, ok := maxCreatedAtMapByActor[actorIDHex]
if ok {
maxCreatedAt = createdAt
Expand Down

0 comments on commit e37c3ea

Please sign in to comment.