composable_indexes/index/
bitmap.rs1use crate::{
2 Index,
3 core::{Insert, Remove, Seal},
4};
5
6pub struct Bitmap {
7 data: roaring::RoaringBitmap,
8}
9
10impl Bitmap {
11 pub fn new() -> Self {
12 Bitmap {
13 data: roaring::RoaringBitmap::new(),
14 }
15 }
16}
17
18impl Default for Bitmap {
19 fn default() -> Self {
20 Self::new()
21 }
22}
23
24impl Index<u32> for Bitmap {
25 #[inline]
26 fn insert(&mut self, _seal: Seal, op: &Insert<u32>) {
27 self.data.insert(*op.new);
28 }
29
30 #[inline]
31 fn remove(&mut self, _seal: Seal, op: &Remove<u32>) {
32 self.data.remove(*op.existing);
33 }
34
35 #[inline]
36 fn update(&mut self, _seal: Seal, op: &crate::core::Update<u32>) {
37 self.data.remove(*op.existing);
38 self.data.insert(*op.new);
39 }
40}
41
42impl Bitmap {
43 pub fn contains(&self, value: u32) -> bool {
44 self.data.contains(value)
45 }
46
47 pub fn contains_range(&self, range: impl core::ops::RangeBounds<u32>) -> bool {
48 self.data.contains_range(range)
49 }
50
51 pub fn rank(&self, value: u32) -> u64 {
52 self.data.rank(value)
53 }
54
55 pub fn count_distinct(&self) -> u64 {
56 self.data.len()
57 }
58
59 pub fn get(&self) -> &roaring::RoaringBitmap {
60 &self.data
61 }
62}
63
64pub struct Treemap {
67 data: roaring::RoaringTreemap,
68}
69
70impl Treemap {
71 pub fn new() -> Self {
72 Treemap {
73 data: roaring::RoaringTreemap::new(),
74 }
75 }
76}
77
78impl Default for Treemap {
79 fn default() -> Self {
80 Self::new()
81 }
82}
83
84impl Index<u64> for Treemap {
85 #[inline]
86 fn insert(&mut self, _seal: Seal, op: &Insert<u64>) {
87 self.data.insert(*op.new);
88 }
89
90 #[inline]
91 fn remove(&mut self, _seal: Seal, op: &Remove<u64>) {
92 self.data.remove(*op.existing);
93 }
94
95 #[inline]
96 fn update(&mut self, _seal: Seal, op: &crate::core::Update<u64>) {
97 self.data.remove(*op.existing);
98 self.data.insert(*op.new);
99 }
100}
101
102impl Treemap {
103 pub fn contains(&self, value: u64) -> bool {
104 self.data.contains(value)
105 }
106
107 pub fn rank(&self, value: u64) -> u64 {
108 self.data.rank(value)
109 }
110
111 pub fn count_distinct(&self) -> u64 {
112 self.data.len()
113 }
114
115 pub fn get(&self) -> &roaring::RoaringTreemap {
116 &self.data
117 }
118}