loop-guard

Guard against loops during tree/graph traversal

Usage no npm install needed!

<script type="module">
  import loopGuard from 'https://cdn.skypack.dev/loop-guard';
</script>

README

Loop Guard guards against loops during tree/graph traversal.

Usage


var createGuard = require('loop-guard');

var guard = createGuard();

function visitNode(node) {
  guard.visit(node);

  for (var i=0; i < node.children.length; i++) {
    var child = node.children[i];

    if (guard.canVisit(child)) {
      visitNode(child);
    }
  }

  guard.leave(node);
}