UNPKG

aws-cdk-lib

Version:

Version 2 of the AWS Cloud Development Kit library

2 lines (1 loc) 963 B
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.iterateDfsPreorder=iterateDfsPreorder,exports.iterateDfsPostorder=iterateDfsPostorder,exports.iterateBfs=iterateBfs;var linked_queue_1=()=>{var tmp=require("./linked-queue");return linked_queue_1=()=>tmp,tmp};function*iterateDfsPreorder(root){const stack=[root];let next=stack.pop();for(;next;)stack.push(...next.node.children.reverse()),yield next,next=stack.pop()}function*iterateDfsPostorder(root){const stack=[{visit:root}];let next=stack.pop();for(;next;)"yield"in next?yield next.yield:(stack.push({yield:next.visit}),stack.push(...next.visit.node.children.reverse().map(visit=>({visit})))),next=stack.pop()}function*iterateBfs(root){const queue=new(linked_queue_1()).LinkedQueue([{construct:root,parent:void 0}]);let next=queue.shift();for(;next;){for(const child of next.construct.node.children)queue.push({construct:child,parent:next.construct});yield next,next=queue.shift()}}