1mod packed_item;
8mod packed_map;
9mod packed_map_builder;
10mod packed_vec;
11
12pub use packed_item::PackedItem;
13pub use packed_map::{Iter, PackedMap};
14pub use packed_map_builder::PackedMapBuilder;
15pub use packed_vec::PackedVec;
16
17pub(crate) fn compute_range_indices<T, R, F>(
18 len: usize,
19 range: R,
20 mut index_of: F,
21) -> std::ops::Range<usize>
22where
23 R: std::ops::RangeBounds<T>,
24 F: FnMut(&T) -> Result<usize, usize>,
25{
26 let start = match range.start_bound() {
27 std::ops::Bound::Included(bound) => index_of(bound).unwrap_or_else(|e| e),
28 std::ops::Bound::Excluded(bound) => match index_of(bound) {
29 Ok(idx) => idx + 1,
30 Err(idx) => idx,
31 },
32 std::ops::Bound::Unbounded => 0,
33 };
34 let end = match range.end_bound() {
35 std::ops::Bound::Included(bound) => match index_of(bound) {
36 Ok(idx) => idx + 1,
37 Err(idx) => idx,
38 },
39 std::ops::Bound::Excluded(bound) => index_of(bound).unwrap_or_else(|e| e),
40 std::ops::Bound::Unbounded => len,
41 };
42
43 let start = std::cmp::min(start, len);
44 let end = std::cmp::max(start, std::cmp::min(end, len));
45 start..end
46}