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

vigna / webgraph-rs / 22046400135

16 Feb 2026 12:49AM UTC coverage: 72.401% (+11.3%) from 61.096%
22046400135

push

github

vigna
fmt

6060 of 8370 relevant lines covered (72.4%)

48832055.95 hits per line

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

56.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::{GlobalArgs, create_parent_dir};
9
use anyhow::{Result, ensure};
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 value_traits::slices::SliceByValue;
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();
8✔
37
    pl.display_memory(true).item_name("indices");
8✔
38

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

43
    if args.epserde {
4✔
44
        let mut perm = Vec::new();
×
45
        for path in args.perms {
×
46
            let p = unsafe { <Vec<usize>>::mmap(&path, Flags::RANDOM_ACCESS) }?;
×
47
            perm.push(p);
×
48
        }
49
        let mut merged = Vec::new();
×
50
        let len = perm[0].uncase().len();
×
51
        ensure!(
×
52
            perm.iter().all(|p| p.uncase().len() == len),
×
53
            "All permutations must have the same length"
54
        );
55

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

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

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