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
/// A node of a petri net; stores the indices to the next and previous nodes.
#[derive(Debug)]
#[repr(C)]
pub struct Node<Id> {
    /// The count of preceding nodes of a node.
    pub prev_count: usize,
    prev_size: usize,
    pub(crate) prev: *mut Id,
    /// The count of following nodes of a node.c
    pub next_count: usize,
    next_size: usize,
    pub(crate) next: *mut Id,
}

#[repr(C)]
pub struct IndexList {
    pub(crate) index: usize,
    next: *mut IndexList,
}

/// A type representing a petri net. It only stores the initial state, not the state used for simulation.
#[derive(Debug)]
#[repr(C)]
pub struct Net {
    pub(crate) transition_count: usize,
    transitions_size: usize,
    pub(crate) transitions: *mut Node<usize>,
    pub(crate) reusable_transitions: *mut IndexList,
    pub(crate) place_count: usize,
    places_size: usize,
    pub(crate) places: *mut Node<usize>,
    pub(crate) reusable_places: *mut IndexList,
    pub(crate) initial_token_counts: *mut usize,
}

#[repr(C)]
struct FireChanges {
    count: usize,
    added_count: usize,
    removed_count: usize,
    active: *mut IndexList,
    added: *mut IndexList,
    removed: *mut IndexList,
}

/// The state of the petri net used for simulation.
#[repr(C)]
pub struct State {
    places_size: usize,
    pub(crate) token_counts: *mut usize,
    transitions_size: usize,
    pub(crate) call_counts: *mut usize,
    fire: FireChanges,
    unfire: FireChanges,
}