mirror of
https://github.com/uutils/coreutils
synced 2024-12-14 07:12:44 +00:00
tsort: Switch to BTreeHash and BTreeSet
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.
This commit is contained in:
parent
82f5fec688
commit
b070506255
1 changed files with 4 additions and 4 deletions
|
@ -6,7 +6,7 @@
|
||||||
// * For the full copyright and license information, please view the LICENSE
|
// * For the full copyright and license information, please view the LICENSE
|
||||||
// * file that was distributed with this source code.
|
// * file that was distributed with this source code.
|
||||||
use clap::{crate_version, Arg, Command};
|
use clap::{crate_version, Arg, Command};
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{BTreeMap, BTreeSet};
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{stdin, BufRead, BufReader, Read};
|
use std::io::{stdin, BufRead, BufReader, Read};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
@ -103,8 +103,8 @@ pub fn uu_app() -> Command {
|
||||||
// but using integer may improve performance.
|
// but using integer may improve performance.
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct Graph {
|
struct Graph {
|
||||||
in_edges: HashMap<String, HashSet<String>>,
|
in_edges: BTreeMap<String, BTreeSet<String>>,
|
||||||
out_edges: HashMap<String, Vec<String>>,
|
out_edges: BTreeMap<String, Vec<String>>,
|
||||||
result: Vec<String>,
|
result: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,7 +122,7 @@ impl Graph {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn init_node(&mut self, n: &str) {
|
fn init_node(&mut self, n: &str) {
|
||||||
self.in_edges.insert(n.to_string(), HashSet::new());
|
self.in_edges.insert(n.to_string(), BTreeSet::new());
|
||||||
self.out_edges.insert(n.to_string(), vec![]);
|
self.out_edges.insert(n.to_string(), vec![]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue