• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

vigna / webgraph-rs / 14999125721

13 May 2025 02:22PM UTC coverage: 49.654% (-5.7%) from 55.382%
14999125721

push

github

zommiommy
wip hyperball cli

4 of 147 new or added lines in 4 files covered. (2.72%)

477 existing lines in 46 files now uncovered.

3663 of 7377 relevant lines covered (49.65%)

25650535.86 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

40.0
/webgraph/src/utils/granularity.rs
1
/*
2
 * SPDX-FileCopyrightText: 2025 Inria
3
 * SPDX-FileCopyrightText: 2025 Sebastiano Vigna
4
 *
5
 * SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
6
 */
7

8
/// Granularity of parallel tasks, specified transparently by nodes or arcs.
9
///
10
/// This enum provides a way to specify the granularity of parallel tasks on
11
/// graphs. It is used by
12
/// [`par_apply`](crate::traits::SequentialLabeling::par_apply) and
13
/// [`par_node_apply`](crate::traits::SequentialLabeling::par_node_apply).
14
///
15
/// Some parallel implementations (e.g.,
16
/// [`par_node_apply`](crate::traits::SequentialLabeling::par_node_apply))
17
/// express naturally the granularity of their tasks via a number of nodes,
18
/// whereas others (e.g.,
19
/// [`par_apply`](crate::traits::SequentialLabeling::par_apply)) via a
20
/// number of arcs. This enum allows to specify the granularity of parallel
21
/// tasks in a transparent way, by nodes or arcs. Conversion between the two
22
/// specifications is done by the methods
23
/// [`arc_granularity`](Self::arc_granularity) and
24
/// [`node_granularity`](Self::node_granularity).
25
#[derive(Debug, Clone, Copy)]
26
pub enum Granularity {
27
    /// Node granularity.
28
    ///
29
    /// For node-based parallelism, each task will be formed by the specified
30
    /// number of nodes. For arc-based parallelism, each task will be formed by
31
    /// a number of nodes that has, tentatively, sum of outdegrees equal to the
32
    /// average outdegree multiplied by the specified number of nodes.
33
    Nodes(usize),
34
    /// Arc granularity.
35
    ///
36
    /// For arc-based parallelism, each task will be formed by a number of nodes
37
    /// that has, tentatively, sum of outdegrees equal to the specified number
38
    /// of arcs. For node-based parallelism, each task will be formed by a
39
    /// number of nodes equal to the specified number of args divided by the
40
    /// average outdegree.
41
    Arcs(u64),
42
}
43

44
impl core::default::Default for Granularity {
45
    /// Returns a default relative granularity of 1000 nodes.
46
    fn default() -> Self {
4✔
47
        Self::Nodes(1000)
4✔
48
    }
49
}
50

51
impl Granularity {
52
    /// Returns a node granularity for a given number of elements and threads.
53
    ///
54
    /// For the variant [`Nodes`](Self::Nodes), the specified number of nodes is
55
    /// returned. For the variant [`Arcs`](Self::Arcs), the number of nodes is
56
    /// computed as the specified number of arcs divided by the average
57
    /// outdegree.
58
    ///
59
    /// # Panics
60
    ///
61
    /// This method will panic if it needs to make a conversion from arc
62
    /// granularity to node granularity and the number of arcs is not provided.
63
    pub fn node_granularity(&self, num_nodes: usize, num_arcs: Option<u64>) -> usize {
7,248✔
64
        match self {
7,248✔
65
            Self::Nodes(n) => *n,
7,248✔
66
            Self::Arcs(n) => {
×
67
                let average_degree = num_arcs.expect(
×
68
                    "You need the number of arcs to convert arc granularity to node granularity",
×
69
                ) as f64
×
70
                    / num_nodes.max(1) as f64;
×
71
                (*n as f64 / average_degree).min(usize::MAX as f64).ceil() as usize
×
72
            }
73
        }
74
    }
75

76
    /// Returns an arc granularity for a given number of nodes and arcs.
77
    ///
78
    /// For the [`Arcs`](Self::Arcs) variant, the specified number of arcs is
79
    /// returned. For the [`Nodes`](Self::Nodes) variant, the number of nodes is
80
    /// computed as the specified number of arcs divided by the average degree.
81
    ///
82
    /// # Panics
83
    ///
84
    /// This method will panic if it needs to make a conversion from node
85
    /// granularity to arc granularity and the number of arcs is not provided.
86
    pub fn arc_granularity(&self, num_nodes: usize, num_arcs: Option<u64>) -> usize {
384✔
87
        match self {
384✔
88
            Self::Nodes(n) => {
384✔
UNCOV
89
                let average_degree = num_arcs.expect(
×
UNCOV
90
                    "You need the number of arcs to convert node granularity to arc granularity",
×
UNCOV
91
                ) as f64
×
UNCOV
92
                    / num_nodes.max(1) as f64;
×
UNCOV
93
                (*n as f64 * average_degree).ceil().max(1.) as usize
×
94
            }
95
            Self::Arcs(n) => *n as usize,
×
96
        }
97
    }
98
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc