UNPKG

mute-structs

Version:

NodeJS module providing an implementation of the LogootSplit CRDT algorithm

60 lines (56 loc) 2.57 kB
"use strict"; /* This file is part of MUTE-structs. Copyright (C) 2017 Matthieu Nicolas, Victorien Elvinger This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero 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 Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. */ Object.defineProperty(exports, "__esModule", { value: true }); var data_validation_1 = require("./data-validation"); var identifierinterval_1 = require("./identifierinterval"); var int32_1 = require("./int32"); var LogootSBlock = /** @class */ (function () { // Creation function LogootSBlock(idInterval, nbElt) { console.assert(int32_1.isInt32(nbElt) && nbElt >= 0, "nbElt must be a non-negative integer"); this.idInterval = idInterval; this.nbElement = nbElt; } LogootSBlock.fromPlain = function (o) { if (data_validation_1.isObject(o) && int32_1.isInt32(o.nbElement) && o.nbElement >= 0) { var id = identifierinterval_1.IdentifierInterval.fromPlain(o.idInterval); if (id !== null) { return new LogootSBlock(id, o.nbElement); // FIXME: Always not mine? } } return null; }; LogootSBlock.prototype.isMine = function (replicaNumber) { return this.idInterval.idBegin.generator === replicaNumber; }; LogootSBlock.prototype.addBlock = function (pos, length) { console.assert(int32_1.isInt32(length) && length > 0, "length must be a positive int32"); this.nbElement += length; this.idInterval = this.idInterval.union(pos, pos + length - 1); }; LogootSBlock.prototype.delBlock = function (nbElt) { console.assert(int32_1.isInt32(nbElt) && nbElt > 0, "nbElt must be a positive int32"); this.nbElement -= nbElt; }; LogootSBlock.prototype.toString = function () { return "{" + this.nbElement + "," + this.idInterval.toString() + "}"; }; return LogootSBlock; }()); exports.LogootSBlock = LogootSBlock; //# sourceMappingURL=logootsblock.js.map