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

vigna / webgraph-rs / 18573498435

16 Oct 2025 08:11PM UTC coverage: 48.064% (+0.04%) from 48.029%
18573498435

push

github

vigna
Docs consistency fix; minimal README.md for CLI and algo

8 of 12 new or added lines in 3 files covered. (66.67%)

433 existing lines in 14 files now uncovered.

3972 of 8264 relevant lines covered (48.06%)

22128303.67 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
    /// Use the parallel compressor.
27
    pub parallel: bool,
28

29
    #[clap(flatten)]
30
    pub num_threads: NumThreadsArg,
31

32
    #[clap(flatten)]
33
    pub memory_usage: MemoryUsageArg,
34

35
    #[clap(flatten)]
36
    pub ca: CompressArgs,
37
}
38

39
pub fn main(global_args: GlobalArgs, args: CliArgs) -> Result<()> {
×
40
    create_parent_dir(&args.dst)?;
×
41

42
    match get_endianness(&args.src)?.as_str() {
×
43
        #[cfg(feature = "be_bins")]
44
        BE::NAME => {
×
45
            if args.parallel {
×
46
                par_transpose::<BE>(global_args, args)
×
47
            } else {
48
                transpose::<BE>(global_args, args)
×
49
            }
50
        }
51
        #[cfg(feature = "le_bins")]
52
        LE::NAME => {
×
53
            if args.parallel {
×
54
                par_transpose::<LE>(global_args, args)
×
55
            } else {
56
                transpose::<LE>(global_args, args)
×
57
            }
58
        }
59
        e => panic!("Unknown endianness: {}", e),
×
60
    }
61
}
62

63
pub fn transpose<E: Endianness>(_global_args: GlobalArgs, args: CliArgs) -> Result<()>
×
64
where
65
    MmapHelper<u32>: CodesReaderFactoryHelper<E>,
66
{
67
    let thread_pool = crate::get_thread_pool(args.num_threads.num_threads);
×
68

69
    // TODO!: speed it up by using random access graph if possible
70
    let seq_graph = webgraph::graphs::bvgraph::sequential::BvGraphSeq::with_basename(&args.src)
×
71
        .endianness::<E>()
72
        .load()?;
73

74
    // transpose the graph
75
    let sorted =
×
76
        webgraph::transform::transpose(&seq_graph, args.memory_usage.memory_usage).unwrap();
×
77

78
    let target_endianness = args.ca.endianness.clone();
×
79
    let dir = Builder::new().prefix("transform_transpose_").tempdir()?;
×
80
    BvComp::parallel_endianness(
81
        &args.dst,
×
82
        &sorted,
×
83
        sorted.num_nodes(),
×
84
        args.ca.into(),
×
85
        &thread_pool,
×
86
        dir,
×
87
        &target_endianness.unwrap_or_else(|| E::NAME.into()),
×
88
    )?;
89

90
    Ok(())
×
91
}
92

93
pub fn par_transpose<E: Endianness>(_global_args: GlobalArgs, args: CliArgs) -> Result<()>
×
94
where
95
    MmapHelper<u32>: CodesReaderFactoryHelper<E>,
96
    for<'a> <MmapHelper<u32> as CodesReaderFactory<E>>::CodesReader<'a>:
97
        BitSeek + Clone + Send + Sync,
98
    BufBitReader<E, WordAdapter<u32, BufReader<std::fs::File>>>: BitRead<E>,
99
    BufBitWriter<E, WordAdapter<usize, BufWriter<std::fs::File>>>: CodesWrite<E>,
100
{
101
    let thread_pool = crate::get_thread_pool(args.num_threads.num_threads);
×
102

103
    // TODO!: speed it up by using random access graph if possible
104
    let seq_graph = webgraph::graphs::bvgraph::BvGraph::with_basename(&args.src)
×
105
        .endianness::<E>()
106
        .load()?;
107

108
    // transpose the graph
109
    let split = webgraph::transform::par_transpose(&seq_graph, args.memory_usage.memory_usage)?;
×
110

111
    // Convert to (node, lender) pairs
112
    let pairs: Vec<_> = split.into();
×
113

114
    let dir = Builder::new().prefix("transform_transpose_").tempdir()?;
×
115
    BvComp::parallel_iter::<E, _>(
116
        &args.dst,
×
NEW
117
        pairs
×
NEW
118
            .into_iter()
×
NEW
119
            .map(|(node, lender)| (node, webgraph::labels::LeftIterator(lender))),
×
120
        seq_graph.num_nodes(),
×
121
        args.ca.into(),
×
122
        &thread_pool,
×
123
        dir,
×
124
    )?;
125
    Ok(())
×
126
}
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