prio_graph/graph_node.rs
1use crate::TransactionId;
2
3/// A single node in a priority graph that is associated with a `Transaction`.
4/// When a node reaches the main queue, the top-level prioritization function can use a reference
5/// to this node to calculate a modified priority for the node, which is only used for
6/// prioritization for the main queue.
7pub struct GraphNode<Id: TransactionId> {
8 /// Whether this node is active, i.e. has not been removed from the main queue.
9 pub(crate) active: bool,
10 /// Number of edges into this node.
11 pub(crate) blocked_by_count: usize,
12 /// Unique edges from this node.
13 /// The number of edges is the same as the number of forks.
14 pub edges: Vec<Id>,
15}
16
17impl<Id: TransactionId> GraphNode<Id> {
18 /// Returns true if the edge was added successfully.
19 /// Edges are only added if the edge is unique.
20 /// Because we always add edges as we insert, the edge is unique if the
21 /// `id` does not match the last element in the `edges` vector.
22 pub fn try_add_edge(&mut self, id: Id) -> bool {
23 if self.edges.last() == Some(&id) {
24 false
25 } else {
26 self.edges.push(id);
27 true
28 }
29 }
30}