mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 19:17:43 +00:00
Merge pull request #4931 from cazou/improve-tsort
tsort: Switch to BTreeMap and BTreeSet
This commit is contained in:
commit
2804af2e56
2 changed files with 12 additions and 4 deletions
|
@ -6,7 +6,7 @@
|
|||
// * For the full copyright and license information, please view the LICENSE
|
||||
// * file that was distributed with this source code.
|
||||
use clap::{crate_version, Arg, Command};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
use std::fs::File;
|
||||
use std::io::{stdin, BufRead, BufReader, Read};
|
||||
use std::path::Path;
|
||||
|
@ -103,8 +103,8 @@ pub fn uu_app() -> Command {
|
|||
// but using integer may improve performance.
|
||||
#[derive(Default)]
|
||||
struct Graph {
|
||||
in_edges: HashMap<String, HashSet<String>>,
|
||||
out_edges: HashMap<String, Vec<String>>,
|
||||
in_edges: BTreeMap<String, BTreeSet<String>>,
|
||||
out_edges: BTreeMap<String, Vec<String>>,
|
||||
result: Vec<String>,
|
||||
}
|
||||
|
||||
|
@ -122,7 +122,7 @@ impl Graph {
|
|||
}
|
||||
|
||||
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![]);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,14 @@ fn test_sort_self_loop() {
|
|||
.stdout_only("first\nsecond\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_sort_floating_nodes() {
|
||||
new_ucmd!()
|
||||
.pipe_in("d d\nc c\na a\nb b")
|
||||
.succeeds()
|
||||
.stdout_only("a\nb\nc\nd\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_no_such_file() {
|
||||
new_ucmd!()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue