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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// SPDX-FileCopyrightText: The im-pathtree authors
// SPDX-License-Identifier: MPL-2.0

use std::sync::Arc;

use crate::{PathTreeTypes, TreeNode};

/// Half-edge to another node in the tree.
///
/// Owns the path segment.
#[derive(Debug, Clone)]
pub struct HalfEdge<T: PathTreeTypes> {
    /// Path segment from the (implicit) source to the target node.
    pub path_segment: T::PathSegment,

    /// The id of the target node.
    pub node_id: T::NodeId,
}

impl<T: PathTreeTypes> PartialEq for HalfEdge<T> {
    fn eq(&self, other: &Self) -> bool {
        let Self {
            path_segment,
            node_id,
        } = self;
        let Self {
            node_id: other_node_id,
            path_segment: other_path_segment,
        } = other;
        node_id.eq(other_node_id) && path_segment.eq(other_path_segment)
    }
}

impl<T: PathTreeTypes> Eq for HalfEdge<T>
where
    T::NodeId: Eq,
    T::PathSegment: Eq,
{
}

/// Half-edge to another node in the tree.
///
/// Borrows the path segment.
#[derive(Debug, Clone)]
pub struct HalfEdgeRef<'a, T: PathTreeTypes> {
    /// Path segment from the (implicit) source to the target node.
    pub path_segment: &'a T::PathSegmentRef,

    /// The id of the target node.
    pub node_id: T::NodeId,
}

impl<'a, T: PathTreeTypes> PartialEq for HalfEdgeRef<'a, T> {
    fn eq(&self, other: &Self) -> bool {
        let Self {
            path_segment,
            node_id,
        } = self;
        let Self {
            node_id: other_node_id,
            path_segment: other_path_segment,
        } = other;
        node_id.eq(other_node_id) && path_segment.eq(other_path_segment)
    }
}

impl<'a, T: PathTreeTypes> Eq for HalfEdgeRef<'a, T>
where
    T::NodeId: Eq,
    T::PathSegmentRef: Eq,
{
}

/// Half-edge to another node in the tree.
///
/// Borrows the path segment.
#[derive(Debug, Clone)]
pub struct HalfEdgeTreeNodeRef<'a, T: PathTreeTypes> {
    /// Path segment from the (implicit) source to the target node.
    pub path_segment: &'a T::PathSegmentRef,

    /// The target node.
    pub node: &'a Arc<TreeNode<T>>,
}