dominikbraun / graph

A library for creating generic graph data structures and modifying, analyzing, and visualizing them.
https://graph.dominikbraun.io
Apache License 2.0
1.8k stars 94 forks source link

Implement `StableTopologicalSort` #127

Closed dominikbraun closed 1 year ago

dominikbraun commented 1 year ago

Closes #61.

CC @deitch, @williamfzc, @geoah

deitch commented 1 year ago

You put this together rather quickly, didn't you? 😄

dominikbraun commented 1 year ago

You put this together rather quickly, didn't you? 😄

Absolutely! 😀

williamfzc commented 1 year ago

Quite frankly, I'm not aware of all the use cases and end-user requirements of the topological sort.

In my case, I do not care about the stable sort part 🤣 . Unstability is OK. But I do care about which nodes belong to which layer (#125).

Something like:

layers := TopologicalSortWithLayer()

// layers[0]
// []int{1, 2, 3, 4, 5, 6}

// layers[1]
// []int{10, 20, 30, 40, 50, 60}
dominikbraun commented 1 year ago

Quite frankly, I'm not aware of all the use cases and end-user requirements of the topological sort.

In my case, I do not care about the stable sort part 🤣 . Unstability is OK. But I do care about which nodes belong to which layer (#125).

Something like:

layers := TopologicalSortWithLayer()

// layers[0]
// []int{1, 2, 3, 4, 5, 6}

// layers[1]
// []int{10, 20, 30, 40, 50, 60}

@williamfzc Ok. "Layer stability" is guaranteed by design, so that's alright.

deitch commented 1 year ago

Thanks again @dominikbraun ; really nicely done. I will pull it into projects as soon as 0.22.0 is cut (I saw you did the prep commit)