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

vigna / webgraph-rs / 11837625908

12 Nov 2024 07:33PM UTC coverage: 53.594% (-0.04%) from 53.631%
11837625908

push

github

vigna
No more Borrow

5 of 13 new or added lines in 6 files covered. (38.46%)

2 existing lines in 2 files now uncovered.

2371 of 4424 relevant lines covered (53.59%)

23193450.13 hits per line

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

8.7
/src/cli/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::cli::*;
9
use crate::prelude::*;
10
use anyhow::Result;
11
use clap::{ArgMatches, Args, Command, FromArgMatches};
12
use dsi_bitstream::prelude::*;
13
use std::path::PathBuf;
14
use tempfile::Builder;
15

16
pub const COMMAND_NAME: &str = "transpose";
17

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

26
    #[clap(flatten)]
27
    pub num_threads: NumThreadsArg,
28

29
    #[clap(flatten)]
30
    pub batch_size: BatchSizeArg,
31

32
    #[clap(flatten)]
33
    pub ca: CompressArgs,
34
}
35

36
pub fn cli(command: Command) -> Command {
18✔
37
    command.subcommand(CliArgs::augment_args(Command::new(COMMAND_NAME)).display_order(0))
18✔
38
}
39

40
pub fn main(submatches: &ArgMatches) -> Result<()> {
×
41
    let args = CliArgs::from_arg_matches(submatches)?;
×
42

43
    create_parent_dir(&args.dst)?;
×
44

45
    match get_endianness(&args.src)?.as_str() {
×
46
        #[cfg(any(
47
            feature = "be_bins",
48
            not(any(feature = "be_bins", feature = "le_bins"))
49
        ))]
50
        BE::NAME => transpose::<BE>(args),
×
51
        #[cfg(any(
52
            feature = "le_bins",
53
            not(any(feature = "be_bins", feature = "le_bins"))
54
        ))]
55
        LE::NAME => transpose::<LE>(args),
×
56
        e => panic!("Unknown endianness: {}", e),
×
57
    }
58
}
59

60
pub fn transpose<E: Endianness + 'static>(args: CliArgs) -> Result<()>
×
61
where
62
    for<'a> BufBitReader<E, MemWordReader<u32, &'a [u32]>>: CodeRead<E> + BitSeek,
63
{
64
    let thread_pool = crate::cli::get_thread_pool(args.num_threads.num_threads);
×
65

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

71
    // transpose the graph
72
    let sorted = crate::transform::transpose(&seq_graph, args.batch_size.batch_size).unwrap();
×
73

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

86
    Ok(())
×
87
}
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