Skip to content

Instantly share code, notes, and snippets.

@BruJu
Created July 1, 2020 11:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BruJu/0f894fee115bff6c4c7d36ae66d5b093 to your computer and use it in GitHub Desktop.
Save BruJu/0f894fee115bff6c4c7d36ae66d5b093 to your computer and use it in GitHub Desktop.
Rust BTreeSet::Range::size_hint testing
// Rust BTreeSet::Range::size_hint testing
use std::collections::btree_set::*;
fn main() {
let mut treeset = BTreeSet::<u32>::new();
for i in 0..78 {
if i % 3 != 1 {
treeset.insert(i);
}
}
for x in treeset.iter() {
print!("{} ", x);
}
print!("\n");
for x in treeset.range(15..35) {
print!("{} ", x)
}
print!("\n");
let sh = treeset.range(15..35).size_hint();
print!("Range hint = {} {}", sh.0,
match sh.1 {
None => -1,
Some(x) => x as i64
}
);
}
// 0 2 3 5 6 8 9 11 12 14 15 17 18 20 21 23 24 26 27 29 30 32 33 35 36 38 39 41 42 44 45 47 48 50 51 53 54 56 57 59 60 62 63 65 66 68 69 71 72 74 75 77
// 15 17 18 20 21 23 24 26 27 29 30 32 33
// Range hint = 0 -1
// I expected Range hint to tell me something like at least 0..21
// but seeing the code of btreeset::range + the result of this experiment makes me sad
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment