Skip to main content

polars_expr/
lib.rs

1#![cfg_attr(
2    feature = "allow_unused",
3    allow(unused, dead_code, irrefutable_let_patterns)
4)] // Maybe be caused by some feature
5pub mod dispatch;
6mod expressions;
7pub mod groups;
8pub mod hash_keys;
9pub mod hot_groups;
10pub mod idx_table;
11pub mod planner;
12pub mod prelude;
13pub mod reduce;
14pub mod state;
15
16use polars_utils::IdxSize;
17
18pub use crate::planner::{ExpressionConversionState, create_physical_expr};
19
20/// An index where the top bit indicates whether a value should be evicted.
21#[derive(Copy, Clone, Debug)]
22#[repr(transparent)]
23pub struct EvictIdx(IdxSize);
24
25impl EvictIdx {
26    #[inline(always)]
27    pub fn new(idx: IdxSize, should_evict: bool) -> Self {
28        debug_assert!(idx >> (IdxSize::BITS - 1) == 0);
29        Self(idx | ((should_evict as IdxSize) << (IdxSize::BITS - 1)))
30    }
31
32    #[inline(always)]
33    pub fn idx(&self) -> usize {
34        (self.0 & (IdxSize::MAX >> 1)) as usize
35    }
36
37    #[inline(always)]
38    pub fn should_evict(&self) -> bool {
39        (self.0 >> (IdxSize::BITS - 1)) != 0
40    }
41
42    pub fn cast_slice(idxs: &[IdxSize]) -> &[EvictIdx] {
43        // SAFETY: same size and align, repr(transparent).
44        unsafe { std::slice::from_raw_parts(idxs.as_ptr() as *const EvictIdx, idxs.len()) }
45    }
46}