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

vigna / webgraph-rs / 22365995929

24 Feb 2026 07:09PM UTC coverage: 71.437% (+0.007%) from 71.43%
22365995929

push

github

vigna
Warning for --parallel

0 of 2 new or added lines in 1 file covered. (0.0%)

1 existing line in 1 file now uncovered.

6285 of 8798 relevant lines covered (71.44%)

51690273.27 hits per line

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

0.0
/cli/src/transform/transpose.rs
1
/*
2
 * SPDX-FileCopyrightText: 2023 Inria
3
 * SPDX-FileCopyrightText: 2023 Tommaso Fontana
4
 *
5
 * SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
6
 */
7

8
use crate::*;
9
use anyhow::Result;
10
use dsi_bitstream::dispatch::factory::CodesReaderFactoryHelper;
11
use dsi_bitstream::prelude::*;
12
use std::io::BufReader;
13
use std::path::PathBuf;
14
use tempfile::Builder;
15
use webgraph::prelude::*;
16

17
#[derive(Parser, Debug)]
18
#[command(name = "transpose", about = "Transposes a BvGraph.", long_about = None)]
19
pub struct CliArgs {
20
    /// The basename of the graph.
21
    pub src: PathBuf,
22
    /// The basename of the transposed graph.
23
    pub dst: PathBuf,
24

25
    #[arg(short, long)]
26
    /// Force usage of the sequential algorithm (does not need offsets).
27
    pub sequential: bool,
28

29
    #[arg(short, long, conflicts_with = "sequential")]
30
    /// No-op for backward compatibility (default is parallel).
31
    pub parallel: bool,
32

33
    #[clap(flatten)]
34
    pub num_threads: NumThreadsArg,
35

36
    #[clap(flatten)]
37
    pub memory_usage: MemoryUsageArg,
38

39
    #[clap(flatten)]
40
    pub ca: CompressArgs,
41
}
42

43
pub fn main(global_args: GlobalArgs, args: CliArgs) -> Result<()> {
×
44
    create_parent_dir(&args.dst)?;
×
45

NEW
46
    if args.parallel {
×
NEW
47
        log::warn!(
×
48
            "The --parallel flag is deprecated and will be removed in a future release. The parallel algorithm is now the default."
49
        );
50
    }
UNCOV
51
    match get_endianness(&args.src)?.as_str() {
×
52
        #[cfg(feature = "be_bins")]
53
        BE::NAME => {
×
54
            if args.sequential {
×
55
                transpose::<BE>(global_args, args)
×
56
            } else {
57
                par_transpose::<BE>(global_args, args)
×
58
            }
59
        }
60
        #[cfg(feature = "le_bins")]
61
        LE::NAME => {
×
62
            if args.sequential {
×
63
                transpose::<LE>(global_args, args)
×
64
            } else {
65
                par_transpose::<LE>(global_args, args)
×
66
            }
67
        }
68
        e => panic!("Unknown endianness: {}", e),
×
69
    }
70
}
71

72
pub fn transpose<E: Endianness>(_global_args: GlobalArgs, args: CliArgs) -> Result<()>
×
73
where
74
    MmapHelper<u32>: CodesReaderFactoryHelper<E>,
75
{
76
    let thread_pool = crate::get_thread_pool(args.num_threads.num_threads);
×
77

78
    // TODO!: speed it up by using random access graph if possible
79
    let seq_graph = webgraph::graphs::bvgraph::sequential::BvGraphSeq::with_basename(&args.src)
×
80
        .endianness::<E>()
81
        .load()?;
82

83
    // transpose the graph
84
    let sorted = webgraph::transform::transpose(&seq_graph, args.memory_usage.memory_usage)?;
×
85

86
    let target_endianness = args.ca.endianness.clone();
×
87
    let dir = Builder::new().prefix("transform_transpose_").tempdir()?;
×
88
    let chunk_size = args.ca.chunk_size;
×
89
    let bvgraphz = args.ca.bvgraphz;
×
90
    let mut builder = BvCompConfig::new(&args.dst)
×
91
        .with_comp_flags(args.ca.into())
×
92
        .with_tmp_dir(&dir);
×
93

94
    if bvgraphz {
×
95
        builder = builder.with_chunk_size(chunk_size);
×
96
    }
97

98
    thread_pool.install(|| {
×
99
        builder.par_comp_lenders_endianness(
×
100
            &sorted,
×
101
            &target_endianness.unwrap_or_else(|| BE::NAME.into()),
×
102
        )
103
    })?;
104

105
    Ok(())
×
106
}
107

108
pub fn par_transpose<E: Endianness>(_global_args: GlobalArgs, args: CliArgs) -> Result<()>
×
109
where
110
    MmapHelper<u32>: CodesReaderFactoryHelper<E>,
111
    for<'a> <MmapHelper<u32> as CodesReaderFactory<E>>::CodesReader<'a>:
112
        BitSeek + Clone + Send + Sync,
113
    BufBitReader<E, WordAdapter<u32, BufReader<std::fs::File>>>: BitRead<E>,
114
    BufBitWriter<E, WordAdapter<usize, BufWriter<std::fs::File>>>: CodesWrite<E>,
115
{
116
    let thread_pool = crate::get_thread_pool(args.num_threads.num_threads);
×
117

118
    let seq_graph = webgraph::graphs::bvgraph::BvGraph::with_basename(&args.src)
×
119
        .endianness::<E>()
120
        .load()?;
121

122
    // transpose the graph
123
    let split = webgraph::transform::transpose_split(&seq_graph, args.memory_usage.memory_usage)?;
×
124

125
    // Convert to (node, lender) pairs
126
    let pairs: Vec<_> = split.into();
×
127

128
    let dir = Builder::new().prefix("transform_transpose_").tempdir()?;
×
129
    let chunk_size = args.ca.chunk_size;
×
130
    let bvgraphz = args.ca.bvgraphz;
×
131
    let mut builder = BvCompConfig::new(&args.dst)
×
132
        .with_comp_flags(args.ca.into())
×
133
        .with_tmp_dir(&dir);
×
134

135
    if bvgraphz {
×
136
        builder = builder.with_chunk_size(chunk_size);
×
137
    }
138

139
    thread_pool
×
140
        .install(|| builder.par_comp_lenders::<E, _>(pairs.into_iter(), seq_graph.num_nodes()))?;
×
141
    Ok(())
×
142
}
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