swh_graph/
impl.rs

1// Copyright (C) 2024  The Software Heritage developers
2// See the AUTHORS file at the top-level directory of this distribution
3// License: GNU General Public License version 3, or any later version
4// See top-level LICENSE file for more information
5
6//! Boring implementations of `SwhGraph*` traits
7
8use std::ops::Deref;
9use std::path::Path;
10
11use crate::graph::*;
12use crate::properties;
13
14impl<T: Deref> SwhGraph for T
15where
16    <T as Deref>::Target: SwhGraph,
17{
18    fn path(&self) -> &Path {
19        self.deref().path()
20    }
21    fn is_transposed(&self) -> bool {
22        self.deref().is_transposed()
23    }
24    fn num_nodes(&self) -> usize {
25        self.deref().num_nodes()
26    }
27    fn has_node(&self, node_id: NodeId) -> bool {
28        self.deref().has_node(node_id)
29    }
30    fn num_arcs(&self) -> u64 {
31        self.deref().num_arcs()
32    }
33    fn has_arc(&self, src_node_id: NodeId, dst_node_id: NodeId) -> bool {
34        self.deref().has_arc(src_node_id, dst_node_id)
35    }
36}
37
38impl<T: Deref> SwhForwardGraph for T
39where
40    <T as Deref>::Target: SwhForwardGraph,
41{
42    type Successors<'succ>
43        = <<T as Deref>::Target as SwhForwardGraph>::Successors<'succ>
44    where
45        Self: 'succ;
46
47    fn successors(&self, node_id: NodeId) -> Self::Successors<'_> {
48        self.deref().successors(node_id)
49    }
50    fn outdegree(&self, node_id: NodeId) -> usize {
51        self.deref().outdegree(node_id)
52    }
53}
54
55impl<T: Deref> SwhLabeledForwardGraph for T
56where
57    <T as Deref>::Target: SwhLabeledForwardGraph,
58{
59    type LabeledArcs<'arc>
60        = <<T as Deref>::Target as SwhLabeledForwardGraph>::LabeledArcs<'arc>
61    where
62        Self: 'arc;
63    type LabeledSuccessors<'succ>
64        = <<T as Deref>::Target as SwhLabeledForwardGraph>::LabeledSuccessors<'succ>
65    where
66        Self: 'succ;
67
68    fn untyped_labeled_successors(&self, node_id: NodeId) -> Self::LabeledSuccessors<'_> {
69        self.deref().untyped_labeled_successors(node_id)
70    }
71}
72
73impl<T: Deref> SwhBackwardGraph for T
74where
75    <T as Deref>::Target: SwhBackwardGraph,
76{
77    type Predecessors<'succ>
78        = <<T as Deref>::Target as SwhBackwardGraph>::Predecessors<'succ>
79    where
80        Self: 'succ;
81
82    fn predecessors(&self, node_id: NodeId) -> Self::Predecessors<'_> {
83        self.deref().predecessors(node_id)
84    }
85    fn indegree(&self, node_id: NodeId) -> usize {
86        self.deref().indegree(node_id)
87    }
88}
89
90impl<T: Deref> SwhLabeledBackwardGraph for T
91where
92    <T as Deref>::Target: SwhLabeledBackwardGraph,
93{
94    type LabeledArcs<'arc>
95        = <<T as Deref>::Target as SwhLabeledBackwardGraph>::LabeledArcs<'arc>
96    where
97        Self: 'arc;
98    type LabeledPredecessors<'succ>
99        = <<T as Deref>::Target as SwhLabeledBackwardGraph>::LabeledPredecessors<'succ>
100    where
101        Self: 'succ;
102
103    fn untyped_labeled_predecessors(&self, node_id: NodeId) -> Self::LabeledPredecessors<'_> {
104        self.deref().untyped_labeled_predecessors(node_id)
105    }
106}
107impl<T: Deref> SwhGraphWithProperties for T
108where
109    <T as Deref>::Target: SwhGraphWithProperties,
110{
111    type Maps = <<T as Deref>::Target as SwhGraphWithProperties>::Maps;
112    type Timestamps = <<T as Deref>::Target as SwhGraphWithProperties>::Timestamps;
113    type Persons = <<T as Deref>::Target as SwhGraphWithProperties>::Persons;
114    type Contents = <<T as Deref>::Target as SwhGraphWithProperties>::Contents;
115    type Strings = <<T as Deref>::Target as SwhGraphWithProperties>::Strings;
116    type LabelNames = <<T as Deref>::Target as SwhGraphWithProperties>::LabelNames;
117    fn properties(
118        &self,
119    ) -> &properties::SwhGraphProperties<
120        Self::Maps,
121        Self::Timestamps,
122        Self::Persons,
123        Self::Contents,
124        Self::Strings,
125        Self::LabelNames,
126    > {
127        self.deref().properties()
128    }
129}