webgraph_cli/run/
llp_combine.rs

1/*
2 * SPDX-FileCopyrightText: 2025 Inria
3 * SPDX-FileCopyrightText: 2025 Sebastiano Vigna
4 * SPDX-FileCopyrightText: 2025 Tommaso Fontana
5 *
6 * SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
7 */
8
9use crate::{GlobalArgs, NumThreadsArg, get_thread_pool};
10use anyhow::Result;
11use clap::Parser;
12use webgraph_algo::{combine_labels, labels_to_ranks};
13
14use std::path::PathBuf;
15
16use super::llp::store_perm;
17
18#[derive(Parser, Debug)]
19#[command(name = "llp-combine", about = "Combine the pre-compute labels from Layered Label Propagation into permutation.", long_about = None)]
20pub struct CliArgs {
21    /// The folder where the LLP labels are stored.
22    pub work_dir: PathBuf,
23
24    /// A filename for the LLP permutation in binary big-endian format.
25    pub perm: PathBuf,
26
27    #[arg(short, long)]
28    /// Save the permutation in ε-serde format.
29    pub epserde: bool,
30
31    /// The number of threads to use.
32    #[command(flatten)]
33    pub num_threads: NumThreadsArg,
34}
35
36pub fn main(_global_args: GlobalArgs, args: CliArgs) -> Result<()> {
37    let thread_pool = get_thread_pool(args.num_threads.num_threads);
38    thread_pool.install(|| -> Result<()> {
39        let labels = combine_labels(args.work_dir)?;
40        log::info!("Combined labels...");
41        let rank_perm = labels_to_ranks(&labels);
42        log::info!("Saving permutation...");
43        store_perm(&rank_perm, &args.perm, args.epserde)?;
44        Ok(())
45    })
46}