webgraph_algo/utils/
mod.rs

1/*
2 * SPDX-FileCopyrightText: 2024 Matteo Dell'Acqua
3 * SPDX-FileCopyrightText: 2025 Sebastiano Vigna
4 *
5 * SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
6 */
7
8//! Utilities.
9
10mod argmax;
11mod argmin;
12
13/// Module containing mathematical utilities.
14pub mod math {
15    pub use super::argmax::*;
16    pub use super::argmin::*;
17}
18
19/// Utility macro to create [`thread_pools`](`rayon::ThreadPool`).
20///
21/// There are two forms of this macro:
22/// * Create a [`ThreadPool`](rayon::ThreadPool) with the default settings:
23/// ```
24/// # use webgraph_algo::thread_pool;
25/// let t: rayon::ThreadPool = thread_pool![];
26/// ```
27/// * Create a [`ThreadPool`](rayon::ThreadPool) with a given number of threads:
28/// ```
29/// # use webgraph_algo::thread_pool;
30/// let t: rayon::ThreadPool = thread_pool![7];
31/// assert_eq!(t.current_num_threads(), 7);
32/// ```
33#[macro_export]
34macro_rules! thread_pool {
35    () => {
36        rayon::ThreadPoolBuilder::new()
37            .build()
38            .expect("Cannot build a ThreadPool with default parameters")
39    };
40    ($num_threads:expr) => {
41        rayon::ThreadPoolBuilder::new()
42            .num_threads($num_threads)
43            .build()
44            .unwrap_or_else(|_| {
45                panic!(
46                    "Cannot build a ThreadPool with default parameters and {} threads",
47                    $num_threads,
48                )
49            })
50    };
51}