logoots-structs
Version:
Provides several data structures to represent a text using a ropes-like structure and manipulating it
69 lines (64 loc) • 1.94 kB
JavaScript
IteratorHelperIdentifier = function (id1, id2) {
this.id1 = id1;
this.id2 = id2;
this.nextOffset = null;
this.result = null;
};
IteratorHelperIdentifier.prototype.compareBase = function () {
var b1 = Utils.iterator(this.id1.base);
var b2 = Utils.iterator(this.id2.base);
while (b1.hasNext() && b2.hasNext()) {
var i1 = b1.next();
var i2 = b2.next();
if (i1 > i2) {
return Utils.Result.B1AfterB2;
}
else if (i1 < i2) {
return Utils.Result.B1BeforeB2;
}
}
if (b1.hasNext()) { //b2 is shorter than b1
this.nextOffset = b1.next();
if (this.nextOffset < this.id2.begin) {
return Utils.Result.B1BeforeB2;
}
else if (this.nextOffset >= this.id2.end) {
return Utils.Result.B1AfterB2;
}
else {
return Utils.Result.B1InsideB2;
}
}
else if (b2.hasNext()) { //b1 is shorter than b2
this.nextOffset = b2.next();
if (this.nextOffset < this.id1.begin) {
return Utils.Result.B1AfterB2;
}
else if (this.nextOffset >= this.id1.end) {
return Utils.Result.B1BeforeB2;
}
else {
return Utils.Result.B2InsideB1;
}
}
else { // both bases have the same size
if (this.id1.end + 1 == this.id2.begin) {
return Utils.Result.B1ConcatB2;
}
else if (this.id1.begin == this.id2.end + 1) {
return Utils.Result.B2ConcatB1;
}
else if (this.id1.end < this.id2.begin) {
return Utils.Result.B1BeforeB2;
}
else {
return Utils.Result.B1AfterB2;
}
}
};
IteratorHelperIdentifier.prototype.computeResults = function() {
if(this.result == null)
this.result = this.compareBase();
return this.result;
};
module.exports = IteratorHelperIdentifier;