Skip to main content

formualizer_eval/engine/
vertex.rs

1/// 🔮 Scalability Hook: Engine-internal vertex identity (opaque for future sharding support)
2#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
3pub struct VertexId(pub(crate) u32);
4
5impl VertexId {
6    pub(crate) fn new(id: u32) -> Self {
7        Self(id)
8    }
9
10    pub(crate) fn as_index(self) -> usize {
11        self.0 as usize
12    }
13
14    // 🔮 Scalability Hook: Future sharding support
15    #[allow(dead_code)]
16    fn shard_id(&self) -> u16 {
17        (self.0 >> 16) as u16
18    }
19
20    #[allow(dead_code)]
21    fn local_id(&self) -> u16 {
22        self.0 as u16
23    }
24}
25
26#[repr(u8)]
27#[derive(Debug, Clone, Copy, PartialEq, Eq)]
28pub enum VertexKind {
29    /// An implicitly created placeholder cell that has not been defined.
30    Empty = 0,
31
32    /// Cell with a literal value (value stored in arena/hashmap)
33    Cell = 1,
34
35    /// Formula that evaluates to a scalar (AST stored separately)
36    FormulaScalar = 2,
37
38    /// Formula that returns an array (AST stored separately)
39    FormulaArray = 3,
40
41    /// Workbook or sheet scoped named range producing a scalar
42    NamedScalar = 4,
43
44    /// Workbook or sheet scoped named range producing an array
45    NamedArray = 5,
46
47    /// Infinite range placeholder (A:A, 1:1)
48    InfiniteRange = 6,
49
50    /// Range reference
51    Range = 7,
52
53    /// External reference
54    External = 8,
55
56    /// Workbook table (ListObject)
57    Table = 9,
58}
59
60impl VertexKind {
61    #[inline]
62    pub fn from_tag(tag: u8) -> Self {
63        match tag {
64            0 => VertexKind::Empty,
65            1 => VertexKind::Cell,
66            2 => VertexKind::FormulaScalar,
67            3 => VertexKind::FormulaArray,
68            4 => VertexKind::NamedScalar,
69            5 => VertexKind::NamedArray,
70            6 => VertexKind::InfiniteRange,
71            7 => VertexKind::Range,
72            8 => VertexKind::External,
73            9 => VertexKind::Table,
74            _ => VertexKind::Empty,
75        }
76    }
77
78    #[inline]
79    pub fn to_tag(self) -> u8 {
80        self as u8
81    }
82}