Skip to main content

pumpkin_core/propagation/
local_id.rs

1use crate::containers::StorageKey;
2
3/// A local id uniquely identifies a variable within a specific propagator. A local id can be
4/// thought of as the index of the variable in the propagator.
5#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
6pub struct LocalId(u32);
7
8impl LocalId {
9    pub const fn from(value: u32) -> Self {
10        LocalId(value)
11    }
12
13    pub fn unpack(self) -> u32 {
14        self.0
15    }
16}
17
18impl StorageKey for LocalId {
19    fn index(&self) -> usize {
20        self.0 as usize
21    }
22
23    fn create_from_index(index: usize) -> Self {
24        LocalId::from(index as u32)
25    }
26}
27
28impl std::fmt::Display for LocalId {
29    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
30        write!(f, "{}", self.0)
31    }
32}