Commit d3536785221ae80c8fa989fe366b449986ee1169
paramitize DFS check condition
Signed-off-by: wanderer <mjbecze@gmail.com>wanderer committed on 8/22/2017, 7:40:01 PM
Parent: ded42bab9d3ec663f4308b94ae68a926196845cb
Files changed
dfsChecker.js | changed |
index.js | changed |
dfsChecker.js | ||
---|---|---|
@@ -6,9 +6,9 @@ | ||
6 | 6 | * @param {object} state - the state containing all of the containers to search |
7 | 7 | * @param {string} root - the root id |
8 | 8 | * @param {Set} nodes - a set of nodes to start searching from |
9 | 9 | */ |
10 | -module.exports = async function DFSchecker (tree, root, nodes) { | |
10 | +module.exports = async function DFSchecker (tree, nodes, checkFn) { | |
11 | 11 | const checkedNodesSet = new Set() |
12 | 12 | let hasRootSet = new Set() |
13 | 13 | const promises = [] |
14 | 14 | |
@@ -53,9 +53,9 @@ | ||
53 | 53 | // mark the node 'checked' |
54 | 54 | checkedNodes.add(id) |
55 | 55 | |
56 | 56 | // check to see if we are at the root |
57 | - if (id === root) { | |
57 | + if (checkFn(id)) { | |
58 | 58 | hasRootSet = checkedNodes |
59 | 59 | return |
60 | 60 | } |
61 | 61 |
index.js | ||
---|---|---|
@@ -182,13 +182,14 @@ | ||
182 | 182 | */ |
183 | 183 | async createStateRoot (ticks) { |
184 | 184 | await this.scheduler.wait(ticks) |
185 | 185 | |
186 | - const unlinked = await DFSchecker(this.tree, this.ROOT_ID, this._nodesToCheck) | |
186 | + const unlinked = await DFSchecker(this.tree, this._nodesToCheck, (id) => { | |
187 | + return this.ROOT_ID === id | |
188 | + }) | |
187 | 189 | for (const id of unlinked) { |
188 | 190 | await this.tree.delete(id) |
189 | 191 | } |
190 | - | |
191 | 192 | return this.graph.flush(this.state) |
192 | 193 | } |
193 | 194 | |
194 | 195 | /** |
Built with git-ssb-web