tcb/graph/middleware/node.rs
1use super::dot::Dot;
2use bit_vec::BitVec;
3use smallvec::SmallVec;
4
5type BV = BitVec<u64>;
6
7/**
8 * Stages that a node in the causal dependency graph can have.
9 */
10#[derive(Debug, Clone, PartialEq, Eq, Copy)]
11pub enum Stage {
12 ///Slot
13 SLT,
14 ///Received
15 RCV,
16 ///Delivered
17 DLV,
18 ///Stable
19 STB,
20}
21
22/**
23 * Struct of a node from the causal dependency graph.
24 */
25#[derive(Debug, Clone)]
26pub struct Node {
27 ///Message dot
28 pub dot: Dot,
29 ///Current stage
30 pub stage: Stage,
31 ///Bit string
32 pub bits: BV,
33 ///Serialized message payload
34 pub payload: Option<Vec<u8>>,
35 ///Message context
36 pub context: Option<Vec<Dot>>,
37 ///Indexes to the predecessors that are still in the graph
38 pub predecessors: SmallVec<[usize; 4]>,
39 ///Indexes to the successors that are still in the graph
40 pub successors: SmallVec<[usize; 4]>,
41}
42
43impl Node {
44 /**
45 * Creates a new node with the passed dot, no payload, no context and stage SLT.
46 *
47 * # Arguments
48 *
49 * `dot` - Message dot
50 */
51 pub fn new(dot: Dot) -> Node {
52 let predecessors = SmallVec::new();
53 let successors = SmallVec::new();
54 let bits = BV::default();
55
56 Node {
57 payload: None,
58 dot,
59 context: None,
60 predecessors,
61 successors,
62 stage: Stage::SLT,
63 bits,
64 }
65 }
66}