4.0.33 • Published 11 months ago

occam-kahn v4.0.33

Weekly downloads
5
License
MIT, Anti-996
Repository
github
Last release
11 months ago

Occam Kahn

An implementation of Kahn's algorithm for Occam.

Contents

Introduction

This algorithm will topologically order a graph, if there are no cycles, otherwise it will report the cycles. The Wikipedia page on topological ordering has a brief explanation.

Installation

With npm:

npm install occam-kahn

You can also clone the repository with Git...

https://github.com/djalbat/occam-kahn.git

...and then install the dependencies with npm from within the project's root directory:

npm install

Usage

A graph can be constructed with the fromVertexLiterals() factory method as follows:

import { Graph } from "../index"

const graph = Graph.fromVertexLiterals([

  ["a", ["b"]],
  ["b", ["c"]],
  ["d", ["c"]],
  ["e", []],
  ["f", ["g"]],
  ["h", ["g"]]

]);

Note that the array of names that is the second element of each literal gives the ancestors of the vertex and not its descendants.

It is possible to check whether there are any cycles present:

const cyclesPresent = graph.areCyclesPresent();

If there are no cycles present, the topologically ordered vertices of the graph are available:

const orderedVertices = graph.getOrderedVertices();

If there are cycles present, they will be amongst the remaining edges:

const remainingEdges = graph.getRemainingEdges();

remainingEdges.forEachEdgeByVertexNames((sourceVertexName, targetVertexName) => {
  ...
});

Rather than iterate through the remaining edges and recover the vertex names yourself you can use the forEachRemainingEdgeByVertexNames() method:

graph.forEachRemainingEdgeByVertexNames((sourceVertexName, targetVertexName) => {
  ...
});

The algorithm will also leave both the incoming and outgoing edges of the topologically ordered vertices intact and these are available by way of the requisite getters:

const firstOrderedVertex = first(orderedVertices),
      incomingEdges = firstOrderedVertex.getIncomingEdges(),
      outgoingEdges = firstOrderedVertex.getOutgoingEdges();

Building

Automation is done with npm scripts, have a look at the package.json file. The pertinent commands are:

npm run build-debug
npm run watch-debug

References

This implementation is based on this gist.

Contact

  • james.smith@djalbat.com
4.0.32

12 months ago

4.0.33

11 months ago

4.0.31

2 years ago

4.0.21

2 years ago

4.0.20

2 years ago

4.0.27

2 years ago

4.0.26

2 years ago

4.0.29

2 years ago

4.0.28

2 years ago

4.0.23

2 years ago

4.0.22

2 years ago

4.0.25

2 years ago

4.0.24

2 years ago

4.0.30

2 years ago

4.0.19

2 years ago

4.0.16

2 years ago

4.0.15

2 years ago

4.0.18

2 years ago

4.0.17

2 years ago

4.0.14

2 years ago

4.0.13

3 years ago

4.0.12

3 years ago

4.0.11

3 years ago

4.0.10

3 years ago

4.0.9

3 years ago

4.0.8

3 years ago

4.0.7

3 years ago

4.0.6

3 years ago

4.0.5

3 years ago

4.0.3

3 years ago

4.0.2

3 years ago

4.0.1

3 years ago

4.0.0

3 years ago

3.0.5

4 years ago

3.0.4

4 years ago

3.0.3

4 years ago

3.0.2

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

2.0.62

4 years ago

2.0.61

4 years ago

2.0.60

4 years ago

2.0.59

5 years ago

2.0.58

5 years ago

2.0.57

5 years ago

2.0.56

5 years ago

2.0.55

5 years ago

2.0.54

5 years ago

2.0.53

5 years ago

2.0.52

5 years ago

2.0.51

5 years ago

2.0.50

5 years ago

2.0.49

5 years ago

2.0.48

6 years ago

2.0.47

6 years ago

2.0.46

6 years ago

2.0.45

6 years ago

2.0.44

6 years ago

2.0.43

6 years ago

2.0.42

6 years ago

2.0.41

6 years ago

2.0.40

6 years ago

2.0.39

7 years ago

2.0.38

7 years ago

2.0.37

7 years ago

2.0.36

7 years ago

2.0.35

7 years ago

2.0.34

7 years ago

2.0.33

7 years ago

2.0.32

7 years ago

2.0.31

7 years ago

2.0.30

7 years ago

2.0.29

7 years ago

2.0.28

7 years ago

2.0.27

7 years ago

2.0.26

7 years ago

2.0.25

7 years ago

2.0.24

7 years ago

2.0.23

7 years ago

2.0.22

7 years ago

2.0.21

7 years ago

2.0.20

7 years ago

2.0.19

7 years ago

2.0.18

7 years ago

2.0.17

7 years ago

2.0.16

7 years ago

2.0.15

7 years ago

2.0.14

7 years ago

2.0.13

7 years ago

2.0.12

7 years ago

2.0.11

7 years ago

2.0.10

7 years ago

2.0.9

7 years ago

2.0.8

7 years ago

2.0.7

7 years ago

2.0.6

7 years ago

2.0.5

7 years ago

2.0.4

7 years ago

2.0.3

7 years ago

2.0.2

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago