custos/graph/
node.rs

1/// A node in the [`Graph`](crate::Graph).
2#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
3pub struct Node {
4    /// The index of the node.
5    pub idx: usize,
6    /// The indices of the nodes that are dependencies of this node.
7    pub deps: [usize; 2],
8    /// The amount of elements a corresponding [`Buffer`](crate::Buffer) has.
9    pub len: usize,
10}
11
12impl Node {
13    /// `true` if the node is a leaf.
14    /// # Example
15    /// ```
16    /// use custos::Node;
17    ///
18    /// let node = Node {
19    ///     idx: 0,
20    ///     deps: [0, 0],
21    ///     len: 10,
22    /// };
23    ///
24    /// assert!(node.is_leaf());
25    ///
26    /// let node = Node {
27    ///     idx: 1,
28    ///     deps: [0, 0],
29    ///     len: 10,
30    /// };
31    /// assert!(!node.is_leaf());
32    /// ```
33    #[inline]
34    pub fn is_leaf(&self) -> bool {
35        self.idx == self.deps[0] && self.idx == self.deps[1]
36    }
37}