itclocks
Version:
An implementation of Interval Tree Clocks in TypeScript
70 lines (69 loc) • 2.03 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 IDs_1 = require("./IDs");
const ID_1 = require("./ID");
class LeafID extends ID_1.ID {
constructor(value) {
super();
this.value = value;
}
get left() {
return null;
}
get right() {
return null;
}
isOne() {
return this.value === 1;
}
isZero() {
return this.value === 0;
}
isLeaf() {
return true;
}
normalize() {
return this;
}
split() {
if (this.isZero())
return [IDs_1.IDs.zero(), IDs_1.IDs.zero()];
return [
IDs_1.IDs.with(IDs_1.IDs.one(), IDs_1.IDs.zero()),
IDs_1.IDs.with(IDs_1.IDs.zero(), IDs_1.IDs.one())
];
}
sum(other) {
if (this.isZero())
return other;
if (other.isZero())
return this;
throw new TypeError("Can't sum " + this + " with " + other);
}
equals(object) {
if (!(object instanceof LeafID))
return false;
let other = object;
return this.value === other.value;
}
toString() {
return this.value.toString();
}
}
exports.LeafID = LeafID;
;