Skip to content

Commit

Permalink
Basic layout process nodes and edges
Browse files Browse the repository at this point in the history
  • Loading branch information
peluja1012 committed Dec 23, 2019
1 parent 1bcdbde commit b9f1ec3
Show file tree
Hide file tree
Showing 6 changed files with 2,045 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

// TODO: type root and children
export function* depthFirstPreorder({ root, children }) {
const nodesToVisit = [root];
while (nodesToVisit.length !== 0) {
const currentNode = nodesToVisit.shift();
nodesToVisit.unshift(...(children(currentNode) || []));
yield currentNode;
}
}

export function* levelOrder({ root, children }) {
let level = [root];
while (level.length !== 0) {
let nextLevel = [];
for (const node of level) {
yield node;
nextLevel.push(...(children(node) || []));
}
level = nextLevel;
nextLevel = [];
}
}
Loading

0 comments on commit b9f1ec3

Please sign in to comment.