In this section are described the transformation functions needed to merge a text document. The document is represented as a list of lines block.Two operations are used in order to update the document :
- AddBlock (p, v) : insert the lines block v at the line p of the document.
- DelBlock (p,o v) : delete the lines block ov starting at the line p of the document.
Two concurrent insertions
T (AddBlock(p1, v1), AddBlock(p2, v2), ) = if (p1 < p2) then return AddBlock (p1, v1) else if (p2 < p1) then return AddBlock (p1 + sizeof(v2), v1) else if (v1 < v2) then return Id () else if (code (v1) < code (v2)) then return AddBlock (p1, v1) else return AddBlock (p1 + sizeof(v2), v1) endif;
- the two insertions occur on two different lines. One of the two insertion is shifted in order to allow the execution of the other, according to the lines number. We use the sizeof function to count the lines number of the block v.
- the two insertions occur on the same line and insert the same content. One of the two insertions is cancelled and is transformed in an Id () operation.
- the two insertions occur on the same line and insert different contents. We use the code (v) function to calculate an integer value from the content of the block. The block which have the smallest code value is put before the other block.
Two concurrent deletions
T(DelBlock(p 1,ov 1), DelBlock(p 2,ov 2)) = if (p 1<p 2) then if (p 1+sizeof(ov 1)-1<p 2) then return DelBlock(p 1,ov 1) else if (p 1+sizeof(ov 1)-1<p 2+sizeof(ov 2)-1) then return DelBlock(p 1,subset(ov 1,1,p 2-p 1)) else return [ DelBlock(p 1,subset(ov 1,1,p 2-p 1)) ; Id() ; DelBlock(p 1,subset(ov 1,p 2+(sizeof(ov 2)-p 1)+1,sizeof(ov 1))) ] endif else if (p 2+sizeof(ov 2)-1<p 1) then return DelBlock(p 1-sizeof(ov 2),ov 1) else if (p 1+sizeof(ov 1)-1<p 2+sizeof(ov 2)-1) then return Id() else if (p 1+sizeof(ov 1)-1=p 2+sizeof(ov 2)-1) then return Id() else return DelBlock(p 2,subset(ov 1,p 2+(sizeof(ov 2)-p 1)+1,sizeof(ov 1))) endif;
- the effects of the two deletions does not overlap. The second (according to the lines number) must be shifted to the top of the document.
- the two deletions overlap. The effect of the first include the effect or a part of the effect of the second. So the transformation return a modified operation that delete what has not already be destroyed. We use a subset(v, p, l) function that return a sub-block of the block v, starting p position, and with lenght l.
Deletion and insertion
This is the most difficult problem.T(AddBlock(p 1,v 1), DelBlock(p 2,ov 2)) = if (p 1 p 2) then return AddBlock(p 1,v 1) else if (p 2+sizeof(ov 2)-1 < p 1) then return AddBlock(p 1-sizeof(ov 2),v 1) else return AddBlock(p 2,append(ov 2,v 1)) endif;T(DelBlock(p 1,ov 1), AddBlock(p 2,v 2)) = if (p 2 p 1) then return DelBlock(p 1+sizeof(v 2),ov 1) else if (p 1+sizeof(ov 1)-1 < p 2) then return DelBlock(p 1,ov 1) else return [ DelBlock(p 2,v 2) ; DelBlock(p 1,ov 1) ; AddBlock(p 1,append(ov 1,v 2)) ] endif;
- the effects of the two operations does not overlap. The second (according to the line numbers) is shifed to allow the execution of the other. The shift is equals to the size block of the other operation.
- the effects of the operations overlap. Only one case is possible : the insertion must be executed on a line n and the deletion destroy a block containing this same line. There is no solution because these two operations are completely in contradiction.
- a beginning delimiter ("<<<<<<<")
- the block that had to be destroy
- a separator ("=======").
- the added block
- a ending delimiter (">>>>>>>")
Rules of Acquisition <<<<<<< removed 34. War is good … 97. Enough… is never enough. ======= 35. Peace is good … >>>>>>> inserted 242. More is good. All is better.