-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tsort: Switch to BTreeMap and BTreeSet #4931
Conversation
oh, super interesting. |
While I think we should merge this because correctness is more important than speed, I was curious what the performance difference would be and this seems to make [1]: On a test case generated with this Python script: import random
N = 10000
for i in range(100*N):
a = random.randint(0,N)
b = random.randint(0,N)
if a != b:
print(f"{min(a, b)} {max(a, b)}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs a test
Although this PR fixes the correctness issue, wouldn't it be better to use a graph library such as petgraph that supports topological sort ? (MIT-licensed) Otherwise, isn't there a linked hash set crate or datastructure in rust ? This way, the ordering would be constant. |
Maybe, but since this is a very small PR, we can accept this first and optimize later. |
Using HashMap and HashSet give a valid topological sort, but the output will change randomly at each run. BTree based structures will guarantee that the output is always ordered in the same way. This also makes the ouptut similar to the output of the C version of the tools, on which some applications rely.
Signed-off-by: Detlev Casanova <[email protected]>
Any idea why |
unrelated |
Using HashMap and HashSet give a valid topological sort, but the output will change randomly at each run.
BTree based structures will guarantee that the output is always ordered in the same way.
This also makes the ouptut similar to the output of the C version of the tools, on which some applications rely.
An example of application that rely on this is the
initramfs-update
program on Debian that usestsort
to create the order of hooks execution. The floating nodes still need to be executed alphabetically to avoid having thebusybox
version of some tools ininitramfs
instead of the full versions. See this issue on Apertis.Although the issue could be fixed in
initramfs-update
, other tools/programs could rely on this ordered output and a stable output for a given input makes sense.