Pudu programming language
Menu
API reference

Std.Graph.topologicalOrder

1 declaration

fn

topologicalOrder: &Std.Graph.Graph[N] -> Option[Array[N]] where N: Ord

This is a callable function.

What it does

The nodes in an order where every node comes before the ones it points at,

or None when there is no such order.

None means a cycle. That is the honest answer rather than a partial list

or an arbitrary tie-break: a caller ordering build steps or resolving

declarations needs to know its input is circular, not to receive an order

that quietly is not one.

Nodes with nothing pointing at them are taken first, and removing them

exposes the next such nodes. If nodes remain when none are left exposed,

every remaining node has something pointing at it, which is a cycle.

Read the signature

  • The text after the name is the type checked by Pudu.
  • Read arrows from left to right: inputs come first, and the final type is returned.
  • & borrows a value for this call instead of moving or copying it.
  • Names inside [ ] are type arguments, such as the item type held by a collection.
  • Option holds Some(value) or None when no value is available.

Back to Std.GraphSearch related declarations