forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic layout process nodes and edges
- Loading branch information
1 parent
1bcdbde
commit b9f1ec3
Showing
6 changed files
with
2,045 additions
and
2 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
x-pack/plugins/endpoint/public/embeddables/resolver/lib/tree_sequencers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = []; | ||
} | ||
} |
Oops, something went wrong.