polars_utils/
marked_usize.rs1#[derive(Copy, Clone, PartialEq, Eq, Hash)]
3pub struct MarkedUsize(usize);
4
5impl MarkedUsize {
6 pub const UNMARKED_MAX: usize = ((1 << (usize::BITS - 1)) - 1);
7
8 #[inline(always)]
9 pub const fn new(idx: usize, marked: bool) -> Self {
10 debug_assert!(idx >> (usize::BITS - 1) == 0);
11 Self(idx | ((marked as usize) << (usize::BITS - 1)))
12 }
13
14 #[inline(always)]
15 pub fn to_usize(&self) -> usize {
16 self.0 & Self::UNMARKED_MAX
17 }
18
19 #[inline(always)]
20 pub fn marked(&self) -> bool {
21 (self.0 >> (usize::BITS - 1)) != 0
22 }
23}