There are a lot of things sorely lacking from the current Rust standard library and/or ecosystem, and this is one of them. (either that, or I am sorely lacking the ability to find stuff on crates.io and github)

Just this week while writing what is supposed to be a little throwaway computational script, I ended up needing to cobble together something like this: (it is basically C++ `multimap`

, stripped to the bare functionality I need)

```
type Key = f64;
type Value = usize;
struct SortedIndices {
keys: Vec<Key>,
values: Vec<Value>,
}
impl SortedIndices {
fn new() -> Self { SortedIndices { keys: vec![], values: vec![] } }
fn insert(&mut self, k: Key, v: Value) {
let i = self.lower_bound(k);
self.keys.insert(i, k); self.values.insert(i, v);
}
fn lower_bound(&self, k: Key) -> usize {
match self.keys.binary_search_by(|b| k.partial_cmp(b).unwrap()) {
Ok(x) => x, Err(x) => x,
}
}
fn upper_bound(&self, k: Key) -> usize {
let mut i = self.lower_bound(k);
for i in i+1..self.keys.len() {
if self.keys[i] > k { return i; }
}
return self.keys.len();
}
fn range(&self, from: Key, to: Key) -> &[Value] {
&self.values[self.lower_bound(from)..self.upper_bound(to)]
}
}
```

*(I havenâ€™t even gotten to test it yet; just writing this post I had to ninja-fix a good 20 or so mistakes in the playpen)*

`BTreeSet`

is just sad-face-making in general. Many many times Iâ€™ve wanted an ordered set of `f64`

s and I almost always end up settling for a sorted vector since the ergonomic cost of wrapping an `f64`

to be `Ord`

is just too high.