swh_graph/views/contiguous_subgraph/
persons.rs

1// Copyright (C) 2025  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//! Implementation of [`properties::Persons`] for [`ContiguousSubgraph`]
7
8use super::*;
9use properties::{NoPersons, OptPersons, PropertiesBackend, PropertiesResult, SwhGraphProperties};
10
11impl<
12        G: SwhGraphWithProperties<Persons: OptPersons>,
13        N: ContractionBackend,
14        MAPS: properties::MaybeMaps,
15        TIMESTAMPS: properties::MaybeTimestamps,
16        CONTENTS: properties::MaybeContents,
17        STRINGS: properties::MaybeStrings,
18        LABELNAMES: properties::MaybeLabelNames,
19    > ContiguousSubgraph<G, N, MAPS, TIMESTAMPS, NoPersons, CONTENTS, STRINGS, LABELNAMES>
20{
21    /// Makes [`OptPersons`] available on this [`ContiguousSubgraph`].
22    ///
23    /// Requires the underlying graph to implement [`OptPersons`].
24    pub fn with_persons(
25        self,
26    ) -> ContiguousSubgraph<
27        G,
28        N,
29        MAPS,
30        TIMESTAMPS,
31        ContiguousSubgraphPersons<G, N>,
32        CONTENTS,
33        STRINGS,
34        LABELNAMES,
35    > {
36        let ContiguousSubgraph {
37            properties:
38                SwhGraphProperties {
39                    path,
40                    num_nodes,
41                    maps,
42                    timestamps,
43                    persons: NoPersons,
44                    contents,
45                    strings,
46                    label_names,
47                    label_names_are_in_base64_order,
48                },
49            inner,
50        } = self;
51
52        ContiguousSubgraph {
53            properties: SwhGraphProperties {
54                path,
55                num_nodes,
56                maps,
57                timestamps,
58                persons: ContiguousSubgraphPersons {
59                    graph: Arc::clone(&inner),
60                },
61                contents,
62                strings,
63                label_names,
64                label_names_are_in_base64_order,
65            },
66            inner,
67        }
68    }
69}
70
71/// View for [`MaybePersons`] that renumbers nodes, as part of [`ContiguousSubgraph`]
72pub struct ContiguousSubgraphPersons<
73    G: SwhGraphWithProperties<Persons: OptPersons>,
74    N: ContractionBackend,
75> {
76    graph: Arc<ContiguousSubgraphInner<G, N>>,
77}
78
79impl<G: SwhGraphWithProperties<Persons: OptPersons>, N: ContractionBackend> PropertiesBackend
80    for ContiguousSubgraphPersons<G, N>
81{
82    type DataFilesAvailability =
83        <<G as SwhGraphWithProperties>::Persons as PropertiesBackend>::DataFilesAvailability;
84}
85impl<G: SwhGraphWithProperties<Persons: OptPersons>, N: ContractionBackend> OptPersons
86    for ContiguousSubgraphPersons<G, N>
87{
88    #[inline(always)]
89    fn author_id(&self, node: NodeId) -> PropertiesResult<'_, Option<u32>, Self> {
90        self.graph
91            .underlying_graph
92            .properties()
93            .persons
94            .author_id(self.graph.contraction.underlying_node_id(node))
95    }
96    #[inline(always)]
97    fn committer_id(&self, node: NodeId) -> PropertiesResult<'_, Option<u32>, Self> {
98        self.graph
99            .underlying_graph
100            .properties()
101            .persons
102            .committer_id(self.graph.contraction.underlying_node_id(node))
103    }
104}