Skip to main content

egui_table_kit/
highlights.rs

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