• No results found

3.3 A log compression algorithm

3.3.2 Definitions

The following definitions are used to describe the relationship between any two oper- ations in a log. Given any editing operation O = Ins/Del[P, N, S], P(O) denotes O’s position parameter, N(O) denotesO’s length parameter, S(O) denotes O’s text parameter, andT(O) = denotesO’s type parameter. Given an initial document state S0 and a logLstoring a sequence of editing operations [O1,· · ·,On] performed onS0,

the document state before the execution ofO1 isS0, and the document state after the

execution of operationOi (1≤i≤n) is denoted asSi =S0 ◦[O1,· · ·, Oi]. Therefore

CTO1 = S0, CTOi = Si−1 = S0 ◦ [O1, · · ·, Oi−1] (1< i ≤ n), and Oi−1 7→ Oi (1< i

≤ n).

Definition 3.1. Operation overlapping relation “⊕”

Given two operations Oa and Ob where Oa 7→ Ob, Oa and Ob are overlapping,

denoted as Oa ⊕Ob, iff one of following conditions holds:

1. T(Oa) = T(Ob) = Ins, and P(Oa)< P(Ob) <P(Oa)+N(Oa).

2. T(Oa) = T(Ob) = Del, and P(Ob) < P(Oa) <P(Ob)+N(Ob).

3. T(Oa) =Insand T(Ob) =Del, andP(Oa)≤P(Ob)<P(Oa)+N(Oa) orP(Ob)

≤ P(Oa) <P(Ob)+N(Ob).

Two operations Oa and Ob are overlapping if their effect regions are overlapping.

104

of a previous insertion operation Oa, then Oa and Ob are overlapping. Second, if a

deletion operationOadeletes a range that falls into the effect region of a later deletion

operation Ob, then Oa and Ob are overlapping. Third, if an insertion operation Oa

inserts a string which or part of which falls into the effect region of a later deletion operationOb, then Oa and Ob are overlapping. Finally, under no circumstance could

an insertion operation overlap with a previous deletion operation because there is no way for a string to be inserted into a nonexistent string (i.e., a string that has already been deleted). For example, as shown in Figure 3.11, a document is initially empty and finally contains characterscandz after five editing operations [O1, · · ·, O5] have

been performed. Operation O1 = Ins[0, 3, abc] inserted 3 characters a, b, and c at

position 0 and operation O2 = Ins[2, 2, xy] inserted 2 characters x and yat position

2 (i.e., after character b). We have O1 ⊕ O2 because the string xy inserted by O2

falls into the string abc inserted by O1. This relation can be further confirmed by

Definition 3.1(1): O1 7→ O2,T(O1) =T(O2) = Ins, and (P(O1)=0) <(P(O2)=2)<

(P(O1)+N(O1)=0+3=3).

abxyc ayc c zc

abc

O1 O2 O3 O4 O5

Figure 3.11: A log for illustrating relationships between operations

Then operation O3 = Del[1, 2, bx] deleted 2 characters b and x at position 1

(i.e., after character a). We have O2 ⊕ O3 because the string bx deleted by O2

includes character x that is part of the string xy inserted by O2. This relation can

be further confirmed by Definition 3.1(3): O2 7→O3,T(O2) = Insand T(O3) = Del,

and (P(O3)=1) < (P(O2)=2) < (P(O3)+N(O3)=1+2=3). Operation O4 = Del[0,

2, ay] deleted 2 characters a and y at position 0. We have O3 ⊕ O4 because the

confirmed by Definition 3.1(2): O3 7→ O4,T(O3) = T(O4) = Del, and (P(O4)=0) <

(P(O3)=1)<(P(O4)+N(O4)=0+2=2). Finally, operationO5 =Ins[0, 1, z] inserted

one characterzat position 0. O5could not overlap withO4according to Definition 3.1. Definition 3.2. Operation adjacent relation “ ”

Given two operationsOaandOb whereOa7→Ob,OaandOb areadjacent, denoted

as Oa Ob,iff one of the following conditions holds:

1. T(Oa) = T(Ob) = Ins, and P(Ob) = P(Oa) or P(Ob) = P(Oa)+N(Oa).

2. T(Oa) = T(Ob) = Del, and P(Oa) = P(Ob)+N(Ob) or P(Oa) = P(Ob).

The same type of two operations are adjacent if their effect regions are adjacent. If an insertion operation Ob inserts a string that is adjacent to the string inserted

by a previous insertion operation Oa, then Oa and Ob are adjacent. If a deletion

operation Ob deletes a range that is adjacent to the range deleted by a previous

deletion operation Oa, then Oa and Ob are adjacent. For instance, in the example

shown in Figure 3.11, if O2 was changed to Ins[0, 2, xy] to insert 2 characters xand

y at position 0, it would be O1 O2 because the string xy inserted by O2 is left

adjacent to the string abc inserted by O1. This relation can be further confirmed by

Definition 3.2(1): O1 7→ O2, T(O1) = T(O2) = Ins, and (P(O2)=0) = P(O1)=0).

Similarly, if O4 was changed toDel[0, 1, a] to delete the character a at position 0, it

would be O3 O4 because the character adeleted byO4 is left adjacent to the string

bx deleted by O3. This relation can be further confirmed by Definition 3.2(2): O3 7→

O4,T(O3) = T(O4) = Del, and (P(O3)=1) = (P(O4)+N(O4)=0+1=1). Definition 3.3. Operation disjointed relation “”

Given two operations Oa and Ob, Oa and Ob are disjointed, denoted as Oa Ob,

iff neitherOa ⊕ Ob nor Oa Ob.

Two operations are disjointed if their effect regions are neither overlapping nor adjacent. The following example shows the relations between any pair of neighbouring

106

editing operations in a log. As shown in Figure 3.12, a document initially contained three characters x,y, and z, which was developed to the state containing characters x, c, 1, 2, and 3 by a sequence of five editing operations saved in the log L = [O1,

O2, O3, O4, O5]. Operation O1 = Ins[3, 1, c] inserted one character c at position 3

(i.e., after character z) and operation O2 =Ins[3, 2, ab] inserted 2 characters a and

b also at position 3. It must be O1 O2 according to Definition 3.2(1): O1 7→ O2, T(O1) = T(O2) = Ins, and (P(O2)=3) = (P(O1)=3). Then operation O3 = Del[2,

2, za] deleted 2 characters z and a at position 2 (i.e., after character y). It must be O2 ⊕ O3 according to Definition 3.1(3): O2 7→ O3, T(O2) = Ins and T(O3) = Del,

and (P(O3)=2) < (P(O2)=3) < (P(O3)+N(O3)=2+2=4). Operation O4 = Del[1,

2, yb] deleted 2 characters y and b at position 1 (i.e., after character x). It must be O3 ⊕ O4 according to Definition 3.1(2): O3 7→ O4, T(O3) = T(O4) = Del, and

(P(O4)=1)<(P(O3)=2)<(P(O4)+N(O4)=1+2=3). Finally, operationO5 =Ins[2,

3, 123] inserted 3 characters 1, 2, and 3 at position 2 (i.e., after characterc). It must be O4 O5 according to Definition 3.3: neither O4 ⊕O5 nor O4 O5.

xyzabc xybc xc xc123

xyzc

xyz O1 O2 O3 O4 O5

Figure 3.12: A log for illustrating relationships between neighbouring operations