Skip to content

Make input independent from internals and check it

So far the main function takes input in the same format that it uses internally, i.e. it takes a sequence of sets of edges that is represented as a vector of u128.

This format is unable to represent more than 128 edges. Moreover, we want to make the number of edges generic (#3).

It would be more flexible to take something like Vec<Vec<u16>> which has no practical limitation with regard to the number of edges. The library function would then validate this input and convert it to the internal format that it needs.

Here are some checks that could be run on the input:

  • Each edge should occur only once or twice.
  • The number of edges should match the number of weights.
  • There should be no missing edges (unused weights).

An advanced variant of this would be to create a Network struct. This struct could be constructed from a Vec<Vec<>> and do the aforementioned checking. Internally, the edges could be represented as a single large Vec<u16> with another Vec of "pointers" into the first one.

Or we could perhaps take a graph, like the one provided by petgraph.