View Source Runbox.Utils.TopologySort (runbox v13.0.3)

Provides topology sorting capabilities.

Summary

Functions

Sort the given network by its topology.

Functions

Link to this function

sort(network, id_fun \\ & &1)

View Source
@spec sort(network :: [{node, [id]}], id_fun :: (node -> id)) ::
  {:ok, sorted_network :: [node]} | {:error, :loop}

Sort the given network by its topology.

The network is given in the form of a list with elements {node, subs} where subs is a list of nodes the node is connected to. The function returns list of nodes sorted by the topology.

The sort is stable - original ordering of the elements is maintained where possible.