Hey!

I'm working on a project where I consolidate some data as `Hashmap<String, Vec<f32>>`

. All of the vectors have the same number of elements in them. I need to sort this hashmap, based on sum of the elements in the vector, and later sum of elements of the vector excluding one of the elements iteratively.

```
trg_map.retain(|_, v| v.iter().filter(|&x| x > &sim_cut).count() > 4); // filter hashmap
for (_, val) in trg_map.iter_mut() {
let sum = val.iter().sum();
val.push(sum);
for lineage in 0..lineage_count {
val.push(sum-val[lineage]);
}
}
let mut map: Vec<(&String, &Vec<f32>)> = trg_map.iter().collect();
map.sort_by(|a,b| a.1[lineage_count].partial_cmp(&b.1[lineage_count]).unwrap());
// output top n entries
// Similarly sort based on sum calculated in the following entries to the vector.
```

The first idea that struck me was to add these sums to the vector itself, and then sort based on that value, but I was wondering if there any better solutions to carrying this out? In specific,

- I was wondering if there is an idiomatic way to sort without adding those values to the vector
- Is it possible to refer a particular element in the vector as a part of the closure?
*i.e.*aiding in calculation of sum without the whole`for`

loop.

Thank you,

aa