Skip to main content

webgraph_cli/transform/
perm.rs

1/*
2 * SPDX-FileCopyrightText: 2026 Sebastiano Vigna
3 *
4 * SPDX-License-Identifier: Apache-2.0 OR MIT
5 */
6
7use crate::*;
8use anyhow::Result;
9use std::path::PathBuf;
10
11#[derive(Parser, Debug)]
12#[command(name = "perm", about = "Permutes a graph in the BV format according to a given permutation.", long_about = None, next_line_help = true)]
13pub struct CliArgs {
14    /// The basename of the graph.​
15    pub src: PathBuf,
16    /// The basename of the permuted graph.​
17    pub dst: PathBuf,
18
19    /// The path to the permutation to apply to the graph.​
20    pub permutation: PathBuf,
21
22    #[arg(long, value_enum, default_value_t)]
23    /// The format of the permutation file.​
24    pub fmt: IntSliceFormat,
25
26    #[arg(short, long)]
27    /// Uses the sequential algorithm (does not need offsets).​
28    pub sequential: bool,
29
30    #[clap(flatten)]
31    pub num_threads: NumThreadsArg,
32
33    #[clap(flatten)]
34    pub memory_usage: MemoryUsageArg,
35
36    #[clap(flatten)]
37    pub ca: CompressArgs,
38
39    #[arg(long, conflicts_with = "sequential")]
40    /// Uses the degree cumulative function to balance work by arcs rather than
41    /// by nodes; the DCF must have been pre-built with `webgraph build dcf`.​
42    pub dcf: bool,
43
44    #[clap(flatten)]
45    pub log_interval: LogIntervalArg,
46}
47
48/// Delegates to [`to bvgraph`](crate::to::bvgraph), which can apply a
49/// permutation while compressing a graph.
50pub fn main(args: CliArgs) -> Result<()> {
51    crate::to::bvgraph::main(crate::to::bvgraph::CliArgs {
52        src: args.src,
53        dst: args.dst,
54        num_threads: args.num_threads,
55        permutation: Some(args.permutation),
56        fmt: args.fmt,
57        sequential: args.sequential,
58        dcf: args.dcf,
59        memory_usage: args.memory_usage,
60        ca: args.ca,
61        log_interval: args.log_interval,
62    })
63}