Skip to main content

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 MIT
7 */
8
9use crate::{IntSliceFormat, 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 = "Combines the pre-computed labels from Layered Label Propagation into a permutation.", long_about = None, next_line_help = true)]
20pub struct CliArgs {
21    /// The folder where the LLP labels are stored as ε-serde files
22    /// (labels_*.bin plus a labels_*.gap objective value per gamma).​
23    pub work_dir: PathBuf,
24
25    /// A filename for the LLP permutation.​
26    pub perm: PathBuf,
27
28    #[arg(long, value_enum, default_value_t)]
29    /// The format of the permutation file.​
30    pub fmt: IntSliceFormat,
31
32    /// The number of threads to use.​
33    #[command(flatten)]
34    pub num_threads: NumThreadsArg,
35}
36
37pub fn main(args: CliArgs) -> Result<()> {
38    let thread_pool = get_thread_pool(args.num_threads.num_threads);
39    thread_pool.install(|| -> Result<()> {
40        let labels = combine_labels(args.work_dir)?;
41        log::info!("Combined labels...");
42        let rank_perm = labels_to_ranks(&labels);
43        log::info!("Saving permutation...");
44        store_perm(&rank_perm, &args.perm, args.fmt)?;
45        Ok(())
46    })
47}