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

vigna / webgraph-rs / 14999125721

13 May 2025 02:22PM UTC coverage: 49.654% (-5.7%) from 55.382%
14999125721

push

github

zommiommy
wip hyperball cli

4 of 147 new or added lines in 4 files covered. (2.72%)

477 existing lines in 46 files now uncovered.

3663 of 7377 relevant lines covered (49.65%)

25650535.86 hits per line

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

38.1
/cli/src/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::{create_parent_dir, GlobalArgs};
9
use anyhow::{ensure, Result};
10
use clap::Parser;
11
use dsi_progress_logger::prelude::*;
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
use webgraph::prelude::*;
18

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

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

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

33
pub fn main(global_args: GlobalArgs, args: CliArgs) -> Result<()> {
4✔
34
    create_parent_dir(&args.dst)?;
8✔
35

36
    let mut pl = ProgressLogger::default();
4✔
UNCOV
37
    pl.display_memory(true).item_name("indices");
×
38

39
    if let Some(duration) = global_args.log_interval {
×
40
        pl.log_interval(duration);
×
41
    }
42

43
    if args.epserde {
×
44
        let mut perm = Vec::new();
×
45
        for path in args.perms {
×
46
            let p = <Vec<usize>>::mmap(&path, Flags::RANDOM_ACCESS)?;
×
47
            perm.push(p);
×
48
        }
49
        let mut merged = Vec::new();
×
50

51
        ensure!(
×
52
            perm.iter().all(|p| p.len() == perm[0].len()),
×
53
            "All permutations must have the same length"
×
54
        );
55

56
        pl.start("Combining permutations...");
×
57
        for i in 0..perm[0].len() {
×
58
            let mut v = i;
×
59
            for p in &perm {
×
60
                v = p[v];
×
61
            }
62
            merged.push(v);
×
63
            pl.light_update();
×
64
        }
65
        pl.done();
×
66
        merged.store(&args.dst)?;
×
67
    } else {
68
        let mut writer = BufWriter::new(std::fs::File::create(&args.dst)?);
8✔
69
        let mut perm = Vec::new();
×
70
        for path in args.perms {
20✔
71
            let p = JavaPermutation::mmap(&path, MmapFlags::RANDOM_ACCESS)?;
24✔
72
            perm.push(p);
×
73
        }
74

75
        ensure!(
4✔
UNCOV
76
            perm.iter()
×
77
                .all(|p| p.as_ref().len() == perm[0].as_ref().len()),
32✔
78
            "All permutations must have the same length"
×
79
        );
80

81
        pl.start("Combining permutations...");
4✔
82
        for i in 0..perm[0].as_ref().len() {
1,302,228✔
83
            let mut v = i;
2,604,456✔
84
            for p in &perm {
6,511,140✔
85
                v = p.get(v);
×
86
            }
87
            writer.write_all(&(v as u64).to_be_bytes())?;
3,906,684✔
88
            pl.light_update();
1,302,228✔
89
        }
90
        pl.done();
4✔
91
    }
92
    Ok(())
4✔
93
}
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