1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use super::dot::Dot;
use bit_vec::BitVec;
use smallvec::SmallVec;

type BV = BitVec<u64>;

/**
 * Stages that a node in the causal dependency graph can have.
 */
#[derive(Debug, Clone, PartialEq, Eq, Copy)]
pub enum Stage {
    ///Slot
    SLT,
    ///Received
    RCV,
    ///Delivered
    DLV,
    ///Stable
    STB,
}

/**
 * Struct of a node from the causal dependency graph.
 */
#[derive(Debug, Clone)]
pub struct Node {
    ///Message dot
    pub dot: Dot,
    ///Current stage
    pub stage: Stage,
    ///Bit string
    pub bits: BV,
    ///Serialized message payload
    pub payload: Option<Vec<u8>>,
    ///Message context
    pub context: Option<Vec<Dot>>,
    ///Indexes to the predecessors that are still in the graph
    pub predecessors: SmallVec<[usize; 4]>,
    ///Indexes to the successors that are still in the graph
    pub successors: SmallVec<[usize; 4]>,
}

impl Node {
    /**
     * Creates a new node with the passed dot, no payload, no context and stage SLT.
     *
     * # Arguments
     *
     * `dot` - Message dot
     */
    pub fn new(dot: Dot) -> Node {
        let predecessors = SmallVec::new();
        let successors = SmallVec::new();
        let bits = BV::default();

        Node {
            payload: None,
            dot,
            context: None,
            predecessors,
            successors,
            stage: Stage::SLT,
            bits,
        }
    }
}