1use std::ops::RangeBounds;
2
3use crate::level::Level;
4use num::cast::AsPrimitive;
5use u24::u24;
6
7pub trait PartitionRead<L: Level> {
8 fn cardinality(&self) -> usize;
10
11 fn is_empty(&self) -> bool;
13
14 fn contains(&self, value: L::Value) -> bool;
16
17 fn position(&self, value: L::Value) -> Option<usize>;
20
21 fn rank(&self, value: L::Value) -> usize;
24
25 fn select(&self, idx: usize) -> Option<L::Value>;
27
28 fn last(&self) -> Option<L::Value>;
30
31 fn iter(&self) -> impl Iterator<Item = L::Value>;
33
34 fn range<R>(&self, range: R) -> impl Iterator<Item = L::Value>
36 where
37 R: RangeBounds<L::Value> + Clone,
38 {
39 let r2 = range.clone();
40 self.iter()
41 .skip_while(move |s| !range.contains(s))
42 .take_while(move |s| r2.contains(s))
43 }
44
45 fn contains_all<R: RangeBounds<L::Value>>(&self, values: R) -> bool;
47
48 fn contains_any<R: RangeBounds<L::Value>>(&self, values: R) -> bool;
50}
51
52pub trait PartitionWrite<L: Level> {
53 fn insert(&mut self, value: L::Value) -> bool;
56
57 fn remove(&mut self, value: L::Value) -> bool;
60
61 fn remove_range<R: RangeBounds<L::Value>>(&mut self, values: R);
63}
64
65#[doc(hidden)]
66pub trait TruncateFrom<T> {
67 fn truncate_from(other: T) -> Self;
68}
69
70macro_rules! impl_truncate_from_usize {
71 ($($ty:ty),*) => {
72 $(
73 impl TruncateFrom<usize> for $ty {
74 #[inline(always)]
75 fn truncate_from(other: usize) -> Self {
76 other.as_()
77 }
78 }
79 )*
80 };
81}
82impl_truncate_from_usize!(u32, u24, u16, u8);
83
84pub trait Optimizable {
85 fn optimize(&mut self);
87}
88
89pub trait Cut<Rhs = Self> {
90 type Out;
91
92 fn cut(&mut self, rhs: &Rhs) -> Self::Out;
95}
96
97pub trait DefaultFull {
98 fn full() -> Self;
99}
100
101pub trait Complement {
102 fn complement(&mut self);
104}