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    /// Get the next [`LocalId`].
14    pub const fn successor(self) -> Self {
15        LocalId(self.0 + 1)
16    }
17
18    pub fn unpack(self) -> u32 {
19        self.0
20    }
21}
22
23impl StorageKey for LocalId {
24    fn index(&self) -> usize {
25        self.0 as usize
26    }
27
28    fn create_from_index(index: usize) -> Self {
29        LocalId::from(index as u32)
30    }
31}
32
33impl std::fmt::Display for LocalId {
34    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
35        write!(f, "{}", self.0)
36    }
37}