0.5.0 • Published 4 months ago

configurable-tree-traversal v0.5.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

configurable-tree-traversal

Can do depth-first traversals like on this picture for abstract trees.

(source: https://en.wikipedia.org/wiki/Tree_traversal)

Examples

To run examples you'll need to have node and you'll need to run npm install.

tree-from-image-example.ts

npm run tsfile examples/tree-from-image-example.ts

const treeData =
  {
    $d: 'F', $c: [
      {
        $d: 'B', $c: [
          { $d: 'A', $c: [] },
          {
            $d: 'D', $c: [
              { $d: 'C', $c: [] },
              { $d: 'E', $c: [] }]
          }]
      },
      {
        $d: 'G', $c: [
          null,
          {
            $d: 'I', $c: [
              { $d: 'H', $c: [] }]
          }]
      }]
  };

const traversal = new DepthFirstTraversal({
  traversableTree: {
    makeRoot: () => treeData,
    makeVertex: (childHint: any) => childHint
  }
});
traversal.addVisitorFor(DepthFirstTraversalOrder.PRE_ORDER, (vertex) => reportVisit(DepthFirstTraversalOrder.PRE_ORDER, vertex.getData()));
traversal.addVisitorFor(DepthFirstTraversalOrder.IN_ORDER, (vertex) => reportVisit(DepthFirstTraversalOrder.IN_ORDER, vertex.getData()));
traversal.addVisitorFor(DepthFirstTraversalOrder.POST_ORDER, (vertex) => reportVisit(DepthFirstTraversalOrder.POST_ORDER, vertex.getData()));
traversal.makeRunner().run();

Stdout

Stdout of tree-from-image-example.ts

traversable-object-example.ts

npm run tsfile examples/traversable-object-example.ts

traversable-object-example-disable-subtree-traversal.ts

npm run tsfile examples/traversable-object-example-disable-subtree-traversal.ts

Same as traversable-object-example.ts, but uses DISABLE_SUBTREE_TRAVERSAL command on vertex B.

traversable-object-example-rewrite-vertex-hints.ts

npm run tsfile examples/traversable-object-example-rewrite-vertex-hints.ts

Same as traversable-object-example.ts, but uses REWRITE_VERTEX_HINTS_ON_PRE_ORDER command on vertex E.

traversable-object-iterable-example.ts

npm run tsfile examples/traversable-object-iterable-example.ts

rewrite-object-example.ts

npm run tsfile examples/rewrite-object-example.ts

Project Status

Not tested beyond examples given and never yet applied to real-life problems.

If for some reason you want to use this as a dependency, please use fixed version (remove ^ from version of configurable-tree-traversal in package.json)

TODO

  1. Breadth-first
  2. Add self-reference test
  3. --
  4. Async traversal
  5. Implementation for FS (with a way to keep fs and tree in sync)
  6. Unit tests
  7. Freeze data at some point? make trees/vertices immutable?
  8. Benchmarks
  9. Breadth-first traversal
0.5.0

4 months ago

0.4.0

4 months ago

0.0.20

2 years ago

0.0.21

2 years ago

0.0.22

2 years ago

0.0.23

2 years ago

0.0.24

2 years ago

0.0.25

2 years ago

0.0.15

2 years ago

0.0.16

2 years ago

0.0.17

2 years ago

0.0.18

2 years ago

0.0.19

2 years ago

0.0.10

2 years ago

0.0.11

2 years ago

0.0.12

2 years ago

0.0.13

2 years ago

0.0.14

2 years ago

0.2.10

2 years ago

0.1.0

2 years ago

0.3.0

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.2.7

2 years ago

0.0.9

2 years ago

0.2.6

2 years ago

0.2.9

2 years ago

0.2.8

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.2.5

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago