rebalance 0.1.4

Portfolio (re-)balancing and simulation
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
use std::mem;

pub fn remove_indices<T: Default>(mut v: Vec<T>, to_be_deleted: &[usize]) -> Vec<T> {
    let mut target_idx = 0;
    for src_idx in 0..v.len() {
        if !to_be_deleted.contains(&src_idx) {
            if src_idx != target_idx {
                v[target_idx] = mem::take(&mut v[src_idx]);
            }
            target_idx += 1;
        }
    }
    v.truncate(target_idx);
    v
}