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
46pub trait PartitionWrite<L: Level> {
47 fn insert(&mut self, value: L::Value) -> bool;
50
51 fn remove(&mut self, value: L::Value) -> bool;
54
55 fn remove_range<R: RangeBounds<L::Value>>(&mut self, values: R);
57}
58
59#[doc(hidden)]
60pub trait TruncateFrom<T> {
61 fn truncate_from(other: T) -> Self;
62}
63
64macro_rules! impl_truncate_from_usize {
65 ($($ty:ty),*) => {
66 $(
67 impl TruncateFrom<usize> for $ty {
68 #[inline(always)]
69 fn truncate_from(other: usize) -> Self {
70 other.as_()
71 }
72 }
73 )*
74 };
75}
76impl_truncate_from_usize!(u32, u24, u16, u8);
77
78pub trait Optimizable {
79 fn optimize(&mut self);
81}
82
83pub trait Cut<Rhs = Self> {
84 type Out;
85
86 fn cut(&mut self, rhs: &Rhs) -> Self::Out;
89}
90
91pub trait DefaultFull {
92 fn full() -> Self;
93}
94
95pub trait Complement {
96 fn complement(&mut self);
98}