127
1. AddresssRecord.getOperationInList()returnstheoperationintheglobal
segmentlistrepresentingthisaddress.
2. AddressRecord.getComparisonLabel()returnstheintegerlabelforagivenad-
dressrecord.
3. Operation.getDestination()returnsthedestinationaddressforagivenopera-
tion.
4. Insertion.getIndex()returnstheindexofaninsertionsegment.
5. Insertion.getNextChunk()returnsthenextsegmentrepresentinganaddresssin
thisinsertion.
6. Insertion.getAddress()returnstheinitialaddressofthisinsertionsegment.
7. AddressfindSegment(path,index)findsthestoredaddressrepresentingthe
positionafterwhich(path,index)isfound.
Thisalgorithmhasafewsomewhatsubtlepoints.Theremovalofthecommonprefixre-
flectsthefactthatidenticalmoveandcopyoperationsdonotcontributetoorderingtheir
addresses.Trickieristhehandlingofaddressesoftheform(I,i).Thiskindofaddresscon-
sistsoftheIDofasingleinsertionandanindexwithinthatinsertion.Aninsertionmay
haveseveralvalidsegmentswithdifferentstartingindices,interruptedbyinterveningdesti-
nationaddresses.UnlikeaddresseswithmovesandcopyIDsintheirpaths,twoaddressesof
theform(I,i)cannotbecomparedintermsoftheirdestinationsortheirindices(exceptin
thespecialcasewheretheyhaveequalpaths).Intheformaldefinitions,thiswasreflected
bytranslatinginsertionstotheirultimatedestinationsintheirgreatestcausalancestor.The
explicitdeterminationofcommonancestorsdoesnotneedtobeperformedintheindex,
sincethelabelsallowustocomparethepositionofsegmentsdirectly.Similarly,thetransi-
tiveclosureofthedestinationrelationisalreadyimplicitlycalculatedbecausethedestina-
tionsarealreadyinsertedintothesegmentlist.
128
booleanisLessThan(path,index)
ifthis.path==paththen
return(this.index<index)
endif/*restis"else"afterreturnabove*/
/*trimanycommonprefix,upto,butnotincluding
thefinalinsertionIDofeitherchange*/
my_path=this.path.trim(path)
path=path.trim(this.path)
ifmy_path.length>1then
/*Icanbeorderedbyamove/copydestination*/
my_label=my_path.head().getDestination().getComparisonLabel()
else
/*Iamorderedbyaninsertionposition*/
my_label=
findSegment(my_path.head(),this.index).getComparisonLabel()
endif
ifpath.length>1then
/*otherisorderedbyherdestination*/
label=path.head().getDestination().getComparisonLabel()
else
/*otherisorderedbyaninsertionsegment*/
label=findSegment(path,
index).getAddress().getcomparisonLabel()
endif
returnmy_label<label
F F F F iii ig g g gu u u ur r r re e e e 6666....5555:::: AAAAllllggggoooorrrriiiitttthhhhmmmm ffffoooorrrr ccccoooommmmppppaaaarrrriiiinnnngggg aaaa nnnnoooonnnn----iiiinnnnddddeeeexxxxeeeedddd aaaaddddddddrrrreeeessssssss
Itsuffices,tofindthestartingaddressofthesegmentcontainingagivenindexforapar-
ticularinsertion.ThisisthefindSegmentfunction.Itisalmostcertainlymostpractical
simplytosearchthesegmentsofaninsertion(whichcanbeeasilykeptlinkedtoeach
other)tofindaninsertionoffset.Itwouldcertainlybepossibletokeepasortedlistofindi-
cesforeachinsertiontoguaranteealogarithmicworst-casesearchtimeifverylargesplit-
tingfactorswerepresentinsomeeditingscenario.
Itisworthmakingcomparisonfordestinationaddressesfastbecauseoftheneedfor
comparisonbasedsearchstructuresformoveanddeletionranges.Ininteractiveediting,
however,asimplerstrategyisavailablesothatsearchandcomparisontimeisnotanissue.
Previous Page Next Page