swh_graph/views/contiguous_subgraph/
label_names.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::LabelNames`] for [`LabelNames`]
7
8use super::*;
9
10impl<
11        G: SwhGraphWithProperties<LabelNames: properties::LabelNames>,
12        N: ContractionBackend,
13        MAPS: properties::MaybeMaps,
14        TIMESTAMPS: properties::MaybeTimestamps,
15        PERSONS: properties::MaybePersons,
16        CONTENTS: properties::MaybeContents,
17        STRINGS: properties::MaybeStrings,
18    >
19    ContiguousSubgraph<G, N, MAPS, TIMESTAMPS, PERSONS, CONTENTS, STRINGS, properties::NoLabelNames>
20{
21    /// Makes [`properties::LabelNames`] available on this [`ContiguousSubgraph`].
22    ///
23    /// Requires the underlying graph to implement [`properties::LabelNames`].
24    pub fn with_label_names(
25        self,
26    ) -> ContiguousSubgraph<
27        G,
28        N,
29        MAPS,
30        TIMESTAMPS,
31        PERSONS,
32        CONTENTS,
33        STRINGS,
34        ContiguousSubgraphLabelNames<G, N>,
35    > {
36        let ContiguousSubgraph {
37            properties:
38                properties::SwhGraphProperties {
39                    path,
40                    num_nodes,
41                    maps,
42                    timestamps,
43                    persons,
44                    contents,
45                    strings,
46                    label_names: properties::NoLabelNames,
47                    label_names_are_in_base64_order,
48                },
49            inner,
50        } = self;
51
52        ContiguousSubgraph {
53            properties: properties::SwhGraphProperties {
54                path,
55                num_nodes,
56                maps,
57                timestamps,
58                persons,
59                contents,
60                strings,
61                label_names: ContiguousSubgraphLabelNames {
62                    graph: Arc::clone(&inner),
63                },
64                label_names_are_in_base64_order,
65            },
66            inner,
67        }
68    }
69}
70
71/// View for [`MaybeMaps`] that renumbers nodes, as part of [`ContiguousSubgraph`
72pub struct ContiguousSubgraphLabelNames<
73    G: SwhGraphWithProperties<LabelNames: properties::LabelNames>,
74    N: ContractionBackend,
75> {
76    graph: Arc<ContiguousSubgraphInner<G, N>>,
77}
78
79impl<G: SwhGraphWithProperties<LabelNames: properties::LabelNames>, N: ContractionBackend>
80    properties::LabelNames for ContiguousSubgraphLabelNames<G, N>
81{
82    type LabelNames<'a>
83        = <<G as SwhGraphWithProperties>::LabelNames as properties::LabelNames>::LabelNames<'a>
84    where
85        Self: 'a;
86
87    fn label_names(&self) -> Self::LabelNames<'_> {
88        self.graph
89            .underlying_graph
90            .properties()
91            .label_names
92            .label_names()
93    }
94}