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

vigna / webgraph-rs / 13547061064

26 Feb 2025 03:09PM UTC coverage: 50.268% (-2.8%) from 53.021%
13547061064

push

github

zommiommy
fixing fuzz test

1 of 1 new or added line in 1 file covered. (100.0%)

324 existing lines in 29 files now uncovered.

2345 of 4665 relevant lines covered (50.27%)

19769434.53 hits per line

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

48.78
/src/cli/perm/comp.rs
1
/*
2
 * SPDX-FileCopyrightText: 2023 Sebastiano Vigna
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::create_parent_dir;
9
use crate::prelude::*;
10
use anyhow::{ensure, Result};
11
use clap::{ArgMatches, Args, Command, FromArgMatches};
12
use epserde::prelude::*;
13
use mmap_rs::MmapFlags;
14
use std::io::{BufWriter, Write};
15
use std::path::PathBuf;
16
use sux::traits::BitFieldSlice;
17

18
pub const COMMAND_NAME: &str = "comp";
19

20
#[derive(Args, Debug)]
21
#[command(about = "Compose multiple permutations into a single one", long_about = None)]
22
pub struct CliArgs {
23
    /// The filename of the resulting permutation in binary big-endian format.
24
    pub dst: PathBuf,
25

26
    /// Filenames of the permutations in binary big-endian format to compose (in order of application).
27
    pub perms: Vec<PathBuf>,
28

29
    #[arg(short, long)]
30
    /// Load and store permutations in ε-serde format.
31
    pub epserde: bool,
32
}
33

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

38
pub fn main(submatches: &ArgMatches) -> Result<()> {
2✔
39
    merge_perms(CliArgs::from_arg_matches(submatches)?)
2✔
40
}
41

42
pub fn merge_perms(args: CliArgs) -> Result<()> {
2✔
43
    let start = std::time::Instant::now();
2✔
44

45
    create_parent_dir(&args.dst)?;
2✔
46

47
    if args.epserde {
2✔
48
        let mut perm = Vec::new();
×
49
        for path in args.perms {
×
50
            let p = <Vec<usize>>::mmap(&path, Flags::RANDOM_ACCESS)?;
×
51
            perm.push(p);
×
52
        }
53
        let mut merged = Vec::new();
×
54

55
        ensure!(
×
56
            perm.iter().all(|p| p.len() == perm[0].len()),
×
57
            "All permutations must have the same length"
×
58
        );
59

60
        for i in 0..perm[0].len() {
×
61
            let mut v = i;
×
62
            for p in &perm {
×
63
                v = p[v];
×
64
            }
65
            merged.push(v);
×
66
        }
67
        merged.store(&args.dst)?;
×
68
    } else {
69
        let mut writer = BufWriter::new(std::fs::File::create(&args.dst)?);
4✔
UNCOV
70
        let mut perm = Vec::new();
×
71
        for path in args.perms {
10✔
72
            let p = JavaPermutation::mmap(&path, MmapFlags::RANDOM_ACCESS)?;
8✔
UNCOV
73
            perm.push(p);
×
74
        }
75
        let mut merged = Vec::new();
2✔
76

77
        ensure!(
2✔
78
            perm.iter()
2✔
79
                .all(|p| p.as_ref().len() == perm[0].as_ref().len()),
6✔
80
            "All permutations must have the same length"
×
81
        );
82

83
        for i in 0..perm[0].as_ref().len() {
651,116✔
UNCOV
84
            let mut v = i;
×
85
            for p in &perm {
3,255,570✔
UNCOV
86
                v = p.get(v);
×
87
            }
UNCOV
88
            merged.push(v);
×
89
        }
90
        for v in merged {
1,302,230✔
91
            writer.write_all(&(v as u64).to_be_bytes())?;
651,114✔
92
        }
93
    }
94
    log::info!("Completed in {} seconds", start.elapsed().as_secs_f64());
4✔
UNCOV
95
    Ok(())
×
96
}
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