im_pathtree/
edge.rs

1// SPDX-FileCopyrightText: The im-pathtree authors
2// SPDX-License-Identifier: MPL-2.0
3
4use std::sync::Arc;
5
6use crate::{PathTreeTypes, TreeNode};
7
8/// Half-edge to another node in the tree.
9///
10/// Owns the path segment.
11#[derive(Debug, Clone)]
12pub struct HalfEdgeOwned<T: PathTreeTypes> {
13    /// Path segment from the (implicit) source to the target node.
14    pub path_segment: T::PathSegmentOwned,
15
16    /// The id of the target node.
17    pub node_id: T::NodeId,
18}
19
20impl<T: PathTreeTypes> PartialEq for HalfEdgeOwned<T> {
21    fn eq(&self, other: &Self) -> bool {
22        let Self {
23            path_segment,
24            node_id,
25        } = self;
26        let Self {
27            node_id: other_node_id,
28            path_segment: other_path_segment,
29        } = other;
30        node_id.eq(other_node_id) && path_segment.eq(other_path_segment)
31    }
32}
33
34impl<T: PathTreeTypes> Eq for HalfEdgeOwned<T>
35where
36    T::NodeId: Eq,
37    T::PathSegmentOwned: Eq,
38{
39}
40
41/// Half-edge to another node in the tree.
42///
43/// Borrows the path segment.
44#[derive(Debug, Clone)]
45pub struct HalfEdge<'a, T: PathTreeTypes> {
46    /// Path segment from the (implicit) source to the target node.
47    pub path_segment: &'a T::PathSegment,
48
49    /// The id of the target node.
50    pub node_id: T::NodeId,
51}
52
53impl<'a, T: PathTreeTypes> PartialEq for HalfEdge<'a, T> {
54    fn eq(&self, other: &Self) -> bool {
55        let Self {
56            path_segment,
57            node_id,
58        } = self;
59        let Self {
60            node_id: other_node_id,
61            path_segment: other_path_segment,
62        } = other;
63        node_id.eq(other_node_id) && path_segment.eq(other_path_segment)
64    }
65}
66
67impl<'a, T: PathTreeTypes> Eq for HalfEdge<'a, T>
68where
69    T::NodeId: Eq,
70    T::PathSegment: Eq,
71{
72}
73
74/// Half-edge to another node in the tree.
75///
76/// Borrows the path segment.
77#[derive(Debug, Clone)]
78pub struct HalfEdgeTreeNode<'a, T: PathTreeTypes> {
79    /// Path segment from the (implicit) source to the target node.
80    pub path_segment: &'a T::PathSegment,
81
82    /// The target node.
83    pub node: &'a Arc<TreeNode<T>>,
84}