Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/crates/polars-utils/src/marked_usize.rs
7884 views
1
/// A usize where the top bit is used as a marked indicator.
2
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
3
pub struct MarkedUsize(usize);
4
5
impl 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
}
24
25