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

vigna / webgraph-rs / 20017908129

08 Dec 2025 05:36AM UTC coverage: 62.065% (+0.4%) from 61.641%
20017908129

push

github

zommiommy
Fix doctests

5435 of 8757 relevant lines covered (62.06%)

46674689.93 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
    let chunk_size = args.ca.chunk_size;
×
81
    let bvgraphz = args.ca.bvgraphz;
×
82
    let mut builder = BvCompConfig::new(&args.dst)
×
83
        .with_comp_flags(args.ca.into())
×
84
        .with_tmp_dir(&dir);
×
85

86
    if bvgraphz {
×
87
        builder = builder.with_chunk_size(chunk_size);
×
88
    }
89

90
    thread_pool.install(|| {
×
91
        builder.par_comp_lenders_endianness(
×
92
            &sorted,
×
93
            sorted.num_nodes(),
×
94
            &target_endianness.unwrap_or_else(|| BE::NAME.into()),
×
95
        )
96
    })?;
97

98
    Ok(())
×
99
}
100

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

111
    let seq_graph = webgraph::graphs::bvgraph::BvGraph::with_basename(&args.src)
×
112
        .endianness::<E>()
113
        .load()?;
114

115
    // transpose the graph
116
    let split = webgraph::transform::transpose_split(&seq_graph, args.memory_usage.memory_usage)?;
×
117

118
    // Convert to (node, lender) pairs
119
    let pairs: Vec<_> = split.into();
×
120

121
    let dir = Builder::new().prefix("transform_transpose_").tempdir()?;
×
122
    let chunk_size = args.ca.chunk_size;
×
123
    let bvgraphz = args.ca.bvgraphz;
×
124
    let mut builder = BvCompConfig::new(&args.dst)
×
125
        .with_comp_flags(args.ca.into())
×
126
        .with_tmp_dir(&dir);
×
127

128
    if bvgraphz {
×
129
        builder = builder.with_chunk_size(chunk_size);
×
130
    }
131

132
    thread_pool
×
133
        .install(|| builder.par_comp_lenders::<E, _>(pairs.into_iter(), seq_graph.num_nodes()))?;
×
134
    Ok(())
×
135
}
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