UNPKG

mute-structs

Version:

NodeJS module providing an implementation of the LogootSplit CRDT algorithm

228 lines 8.11 kB
var Stats = /** @class */ (function () { function Stats(rope) { this.documentLength = rope.str.length; this.treeHeight = rope.height; this.nodeNumber = 0; this.nodeLengths = []; this.identifierLengths = []; this.nodesStats = { max: 0, min: -1, mean: 0, median: 0, lengthRepartition: new Map(), }; this.identifiersStats = { max: 0, min: -1, mean: 0, median: 0, lengthRepartition: new Map(), }; this.compute(rope); } Object.defineProperty(Stats.prototype, "numberOfNodes", { get: function () { return this.nodeNumber; }, enumerable: true, configurable: true }); Object.defineProperty(Stats.prototype, "maxNodeLength", { get: function () { return this.nodesStats.max; }, enumerable: true, configurable: true }); Object.defineProperty(Stats.prototype, "minNodeLength", { get: function () { return this.nodesStats.min; }, enumerable: true, configurable: true }); Object.defineProperty(Stats.prototype, "meanNodeLength", { get: function () { return this.nodesStats.mean; }, enumerable: true, configurable: true }); Object.defineProperty(Stats.prototype, "medianNodeLength", { get: function () { return this.nodesStats.median; }, enumerable: true, configurable: true }); Object.defineProperty(Stats.prototype, "repartitionNodeLength", { get: function () { return this.nodesStats.lengthRepartition; }, enumerable: true, configurable: true }); Object.defineProperty(Stats.prototype, "repartitionNodeLengthString", { get: function () { var arr = Array.from(this.nodesStats.lengthRepartition); arr.sort(function (a, b) { return a[0] - b[0]; }); var str = ""; arr.forEach(function (entry) { str += "(" + entry[0] + ", " + entry[1] + "), "; }); return str; }, enumerable: true, configurable: true }); Object.defineProperty(Stats.prototype, "maxIdentifierLength", { get: function () { return this.identifiersStats.max; }, enumerable: true, configurable: true }); Object.defineProperty(Stats.prototype, "minIdentifierLength", { get: function () { return this.identifiersStats.min; }, enumerable: true, configurable: true }); Object.defineProperty(Stats.prototype, "meanIdentifierLength", { get: function () { return this.identifiersStats.mean; }, enumerable: true, configurable: true }); Object.defineProperty(Stats.prototype, "medianIdentifierLength", { get: function () { return this.identifiersStats.median; }, enumerable: true, configurable: true }); Object.defineProperty(Stats.prototype, "repartitionIdentifierLength", { get: function () { return this.identifiersStats.lengthRepartition; }, enumerable: true, configurable: true }); Object.defineProperty(Stats.prototype, "repartitionIdentifierLengthString", { get: function () { var arr = Array.from(this.identifiersStats.lengthRepartition); arr.sort(function (a, b) { return a[0] - b[0]; }); var str = ""; arr.forEach(function (entry) { str += "(" + entry[0] + ", " + entry[1] + "), "; }); return str; }, enumerable: true, configurable: true }); Stats.prototype.toString = function () { var str = ""; str += "Document stats : \n"; str += "\t Document length : " + this.documentLength + "\n"; str += "\t Number of nodes : " + this.numberOfNodes + "\n"; str += "\t Height of the tree : " + this.treeHeight + "\n"; str += "\t Nodes : " + "\n"; str += "\t\tMax length : " + this.maxNodeLength + "\n"; str += "\t\tMin length : " + this.minNodeLength + "\n"; str += "\t\tMean length : " + this.meanNodeLength + "\n"; str += "\t\tMedian length : " + this.medianNodeLength + "\n"; str += "\t\tLength repartition : " + this.repartitionNodeLengthString + "\n"; str += "\t Identifier : " + "\n"; str += "\t\tMax length : " + this.maxIdentifierLength + "\n"; str += "\t\tMin length : " + this.minIdentifierLength + "\n"; str += "\t\tMean length : " + this.meanIdentifierLength + "\n"; str += "\t\tMedian length : " + this.medianIdentifierLength + "\n"; str += "\t\tLength repartition : " + this.repartitionIdentifierLengthString + "\n"; return str; }; Stats.prototype.compute = function (rope) { this.nodeNumber = this.recCompute(rope.root); this.nodeLengths = this.nodeLengths.sort(function (a, b) { return a - b; }); this.identifierLengths = this.identifierLengths.sort(function (a, b) { return a - b; }); this.nodesStats.mean /= this.nodeNumber; var N = this.nodeLengths.length; this.nodesStats.median = N % 2 === 0 ? (this.nodeLengths[N / 2] + this.nodeLengths[N / 2 + 1]) / 2 : this.nodeLengths[Math.ceil(N / 2)]; this.identifiersStats.mean /= this.nodeNumber; var M = this.identifierLengths.length; this.identifiersStats.median = M % 2 === 0 ? (this.identifierLengths[M / 2] + this.identifierLengths[M / 2 + 1]) / 2 : this.identifierLengths[Math.ceil(M / 2)]; }; Stats.prototype.recCompute = function (rope) { if (!rope) { return 0; } // node stats var nLength = rope.length; this.nodeLengths.push(nLength); this.nodesStats.max = this.nodesStats.max < nLength ? nLength : this.nodesStats.max; this.nodesStats.min = this.nodesStats.min === -1 ? nLength : this.nodesStats.min > nLength ? nLength : this.nodesStats.min; this.nodesStats.mean += nLength; if (this.nodesStats.lengthRepartition.has(nLength)) { var n = this.nodesStats.lengthRepartition.get(nLength); if (n) { this.nodesStats.lengthRepartition.set(nLength, n + 1); } } else { this.nodesStats.lengthRepartition.set(nLength, 1); } // identifier stats var iLength = rope.getIdBegin().length; this.identifierLengths.push(iLength); this.identifiersStats.max = this.identifiersStats.max < iLength ? iLength : this.identifiersStats.max; this.identifiersStats.min = this.identifiersStats.min === -1 ? iLength : this.identifiersStats.min > iLength ? iLength : this.identifiersStats.min; this.identifiersStats.mean += iLength; if (this.identifiersStats.lengthRepartition.has(iLength) && this.identifiersStats.lengthRepartition) { var n = this.identifiersStats.lengthRepartition.get(iLength); if (n) { this.identifiersStats.lengthRepartition.set(iLength, n + 1); } } else { this.identifiersStats.lengthRepartition.set(iLength, 1); } return this.recCompute(rope.left) + 1 + this.recCompute(rope.right); }; return Stats; }()); export { Stats }; //# sourceMappingURL=stats.js.map