itclocks
Version:
An implementation of Interval Tree Clocks in TypeScript
78 lines (77 loc) • 2.37 kB
JavaScript
/**
* Copyright (C) 2017 Gabriel Batista Galli
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
Object.defineProperty(exports, "__esModule", { value: true });
const Occurrence_1 = require("./Occurrence");
const Occurrences_1 = require("./Occurrences");
class LeafOccurrence extends Occurrence_1.Occurrence {
constructor(value) {
super();
this.value = value || 0;
}
get left() {
return null;
}
set left(left) {
throw new ReferenceError("Cannot set left node on a leaf");
}
get right() {
return null;
}
set right(right) {
throw new ReferenceError("Cannot set right node on a leaf");
}
max() {
return this.value;
}
min() {
return this.value;
}
maxDepth(depth) {
return depth;
}
isLeaf() {
return true;
}
lift(m) {
return new LeafOccurrence(this.value + m);
}
sink(m) {
return new LeafOccurrence(this.value - m);
}
normalize() {
return this;
}
leq(other) {
return this.value <= other.value;
}
join(other) {
if (other.isLeaf())
return new LeafOccurrence(Math.max(this.value, other.value));
return Occurrences_1.Occurrences.with(this.value, Occurrences_1.Occurrences.zero(), Occurrences_1.Occurrences.zero()).join(other);
}
equals(object) {
if (!(object instanceof LeafOccurrence))
return false;
const other = object;
return this.value === other.value;
}
toString() {
return this.value.toString();
}
}
exports.LeafOccurrence = LeafOccurrence;
;