Odds and ends — collection miscellania. Extra functionality for slices (`.find()`, `RevSlice`), strings and other things. Debug checked variants of `get_unchecked` and `slice_unchecked`, and extra methods for strings and vectors: `repeat`, `insert_str` and `splice`. Things in odds may move to more appropriate crates if we find them.
#![feature(test)]externcrate test;usestd::mem::{size_of, size_of_val};usetest::Bencher;externcrate odds;useodds::slice::split_aligned_for;useodds::slice::unalign::UnalignedIter;fncount_ones(data:&[u8])->u32{letmut total =0;let(head, mid, tail)=split_aligned_for::<[u64;2]>(data);
total += head.iter().map(|x|x.count_ones()).sum();
total += mid.iter().map(|x|x[0].count_ones()+ x[1].count_ones()).sum();
total += tail.iter().map(|x|x.count_ones()).sum();
total
}fnunalign_count_ones(data:&[u8])->u32{letmut total =0;letmut iter =UnalignedIter::<u64>::from_slice(data);
total +=(&mut iter).map(|x|x.count_ones()).sum();
total += iter.tail().map(|x|x.count_ones()).sum();
total
}#[bench]fnsplit_count_ones(b:&mut Bencher){let v =vec![3u8;127];
b.iter(||{count_ones(&v)});
b.bytes =size_of_val(&v[..])asu64;}#[bench]fnbench_unalign_count_ones(b:&mut Bencher){let v =vec![3u8;127];
b.iter(||{unalign_count_ones(&v)});
b.bytes =size_of_val(&v[..])asu64;}