egui_table_kit/
highlights.rs1use roaring::RoaringBitmap;
4use serde::{Deserialize, Serialize};
5
6#[derive(Clone, Debug, Default, Serialize, Deserialize)]
8pub struct Highlights(pub [RoaringBitmap; 10]);
9
10impl Highlights {
11 #[must_use]
13 pub fn get_usize(&self, index: usize) -> Option<u8> {
14 self.get(index as u32)
15 }
16
17 pub fn insert(&mut self, typ: u8, index: u32) -> bool {
19 self.0
20 .get_mut(typ as usize)
21 .is_some_and(|bmp| bmp.insert(index))
22 }
23
24 #[must_use]
26 pub fn get(&self, index: u32) -> Option<u8> {
27 self.0.iter().enumerate().find_map(|(i, bmp)| {
28 if bmp.contains(index) {
29 Some(i as u8)
30 } else {
31 None
32 }
33 })
34 }
35
36 pub fn insert_map(&mut self, typ: u8, map: &RoaringBitmap) {
38 self.0.iter_mut().enumerate().for_each(|(i, bmp)| {
39 if i as u8 == typ {
40 *bmp |= map;
41 } else {
42 *bmp -= map;
43 }
44 });
45 }
46
47 pub fn remove_map(&mut self, map: &RoaringBitmap) {
49 for bmp in &mut self.0 {
50 *bmp -= map;
51 }
52 }
53}