diff --git a/lib/linearizer.js b/lib/linearizer.js index 34707f63..0ee72188 100644 --- a/lib/linearizer.js +++ b/lib/linearizer.js @@ -161,39 +161,6 @@ module.exports = class Linearizer { } } - /* Tip ordering methods */ - - _orderTip () { - const tip = [] - const stack = [...this.tails] - - while (stack.length) { - const node = stack.pop() - if (node.ordering) continue - - node.ordering = node.dependencies.size - stack.push(...node.dependents) - } - - stack.push(...this.tails) - stack.sort(keySort) - - while (stack.length) { - const node = stack.pop() - tip.push(node) - - const batch = [] - - for (const dep of node.dependents) { - if (--dep.ordering === 0) batch.push(dep) - } - - if (batch.length > 0) stack.push(...batch.sort(keySort)) - } - - return tip - } - /* Ack methods */ shouldAck (writer, pending = false) { @@ -390,20 +357,14 @@ module.exports = class Linearizer { } } -// if same key, earlier node is first function tieBreak (a, b) { - return keySort(a, b) > 0 // keySort sorts high to low + return Topolist.compare(a, b) < 0 // lowest key wis } function getFirst (set) { return set[Symbol.iterator]().next().value } -function keySort (a, b) { - const cmp = b4a.compare(a.writer.core.key, b.writer.core.key) - return cmp === 0 ? b.length - a.length : -cmp -} - function sameNode (a, b) { return b4a.equals(a.key, b.writer.core.key) && a.length === b.length } diff --git a/lib/topolist.js b/lib/topolist.js index 946c7ab9..f728032b 100644 --- a/lib/topolist.js +++ b/lib/topolist.js @@ -8,6 +8,10 @@ module.exports = class TopoList { this.shared = 0 } + static compare (a, b) { + return cmp(a, b) + } + mark () { this.shared = this.tip.length this.undo = 0