std.lib.sort

find-cycle

added in 4.0

(find-cycle g)

finds a cycle in a directed graph, returning a closed path a b c a or nil

(find-cycle {:a #{:b}, :b #{:c}, :c #{:b}}) => :b :c :b

(find-cycle {:a #{:b}, :b #{:a}}) => :a :b :a

(find-cycle {:a #{:a}}) => :a :a

(find-cycle {:a #{:b}, :b #{}}) => nil

hierarchical-sort

added in 3.0

(hierarchical-sort idx)

prunes a hierarchy of descendants into a directed graph

(hierarchical-sort {1 #{2 3 4 5 6} 2 #{3 5 6} 3 #{5 6} 4 #{} 5 #{6} 6 #{}}) => {1 #{4 2} 2 #{3} 3 #{5} 4 #{} 5 #{6} 6 #{}}

hierarchical-top

added in 3.0

(hierarchical-top idx)

find the top node for the hierarchy of descendants

(hierarchical-top {1 #{2 3 4 5 6} 2 #{3 5 6} 3 #{5 6} 4 #{} 5 #{6} 6 #{}}) => 1

topological-sort

added in 3.0

(topological-sort g)(topological-sort g l s)

sorts a directed graph into its dependency order

(topological-sort {:a #{:b :c}, :b #{:d :e}, :c #{:e :f}, :d #{}, :e #{:f}, :f nil}) => :f :d :e :b :c :a

(topological-sort {:a #{:b}, :b #{:a}}) => (throws)

topological-sort-order-by-deps

added in 4.0

(topological-sort-order-by-deps g sorted-list)

Refines a topologically sorted list by sorting nodes at each dependency level by their dependency count. Takes the dependency graph and a pre-sorted list. A secondary sort is done on the node key to ensure a stable ordering.

topological-top

added in 3.0

(topological-top g)

nodes that have no other nodes that are dependent on them (topological-top {:a #{} :b #{:a}}) => #{:b}