Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ bitflags = { version = "2", default-features = false }
serde = { version = "1", optional = true }

[dev-dependencies]
clap = { version = "4", features = ["derive"] }
noargs = "0.4.1"
rand = "0.9"
serde_json = { version = "1" }

Expand Down
2 changes: 1 addition & 1 deletion benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn bench_removal(b: &mut test::Bencher) {
}

let mut values = (0..MAX).collect::<Vec<_>>();
values.shuffle(&mut rand::thread_rng());
values.shuffle(&mut rand::rng());

let mut values = values.iter().cycle();
b.iter(|| {
Expand Down
35 changes: 22 additions & 13 deletions examples/insert_lines.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
use clap::Parser;
use patricia_tree::PatriciaSet;
use std::collections::{BTreeSet, HashSet};
use std::io::BufRead;

#[derive(Parser)]
struct Args {
#[clap(
long,
default_value = "patricia",
value_parser = clap::builder::PossibleValuesParser::new(["patricia", "hash", "btree", "count"])
)]
kind: String,
}
fn main() -> noargs::Result<()> {
let mut args = noargs::raw_args();
noargs::HELP_FLAG.take_help(&mut args);

fn main() {
let args = Args::parse();
let kind = noargs::opt("kind")
.doc("Data structure kindt")
.ty("patricia | hash | btree | count")
.default("patricia")
.take(&mut args)
.then(|a| {
let value = a.value();
match value {
"patricia" | "hash" | "btree" | "count" => Ok(value.to_string()),
_ => Err("must be one of: patricia, hash, btree, count"),
}
})?;
if let Some(help) = args.finish()? {
print!("{help}");
return Ok(());
}

match args.kind.as_str() {
match kind.as_str() {
"patricia" => {
let mut set = PatriciaSet::new();
each_line(|line| {
Expand Down Expand Up @@ -47,6 +54,8 @@ fn main() {
}
_ => unreachable!(),
}

Ok(())
}

fn each_line<F>(mut f: F)
Expand Down
2 changes: 1 addition & 1 deletion src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ mod tests {
#[cfg_attr(miri, ignore)]
fn large_map_works() {
let mut input = (0..10000).map(|i| (i.to_string(), i)).collect::<Vec<_>>();
input.shuffle(&mut rand::thread_rng());
input.shuffle(&mut rand::rng());

// Insert
let mut map = input.iter().cloned().collect::<PatriciaMap<_>>();
Expand Down