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

vigna / webgraph-rs / 23365769388

20 Mar 2026 10:52PM UTC coverage: 68.228% (-3.0%) from 71.245%
23365769388

push

github

vigna
No le_bins,be_bins for webgraph

6655 of 9754 relevant lines covered (68.23%)

46582760.24 hits per line

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

82.76
/cli/src/build/offsets.rs
1
/*
2
 * SPDX-FileCopyrightText: 2023 Inria
3
 * SPDX-FileCopyrightText: 2023 Tommaso Fontana
4
 * SPDX-FileCopyrightText: 2026 Sebastiano Vigna
5
 *
6
 * SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
7
 */
8

9
use crate::LogIntervalArg;
10
use anyhow::{Context, Result};
11
use clap::Parser;
12
use dsi_bitstream::{dispatch::factory::CodesReaderFactoryHelper, prelude::*};
13
use dsi_progress_logger::prelude::*;
14
use std::path::PathBuf;
15
use webgraph::prelude::*;
16

17
#[derive(Parser, Debug)]
18
#[command(name = "offsets", about = "Builds the offsets file of a graph.", long_about = None, next_line_help = true)]
19
pub struct CliArgs {
20
    /// The basename of the graph.​
21
    pub basename: PathBuf,
22

23
    #[clap(flatten)]
24
    pub log_interval: LogIntervalArg,
25
}
26

27
pub fn main(args: CliArgs) -> Result<()> {
15✔
28
    match get_endianness(&args.basename)?.as_str() {
45✔
29
        #[cfg(feature = "be_bins")]
30
        BE::NAME => build_offsets::<BE>(args),
45✔
31
        #[cfg(feature = "le_bins")]
32
        LE::NAME => build_offsets::<LE>(args),
×
33
        e => panic!("Unknown endianness: {}", e),
×
34
    }
35
}
36

37
pub fn build_offsets<E: Endianness + 'static>(args: CliArgs) -> Result<()>
15✔
38
where
39
    MmapHelper<u32>: CodesReaderFactoryHelper<E>,
40
    for<'a> LoadModeCodesReader<'a, E, Mmap>: BitSeek,
41
{
42
    // Creates the sequential iterator over the graph
43
    let seq_graph = BvGraphSeq::with_basename(&args.basename)
45✔
44
        .endianness::<E>()
45
        .load()?;
46
    let offsets = args.basename.with_extension(OFFSETS_EXTENSION);
30✔
47
    // create a bit writer on the file
48
    let mut writer = buf_bit_writer::from_path::<BE, usize>(&offsets)
45✔
49
        .with_context(|| format!("Could not create {}", offsets.display()))?;
15✔
50
    // progress bar
51
    let mut pl = progress_logger![
30✔
52
        display_memory = true,
×
53
        item_name = "node",
×
54
        expected_updates = Some(seq_graph.num_nodes()),
15✔
55
    ];
56
    if let Some(duration) = args.log_interval.log_interval {
15✔
57
        pl.log_interval(duration);
×
58
    }
59
    pl.start("Computing offsets...");
30✔
60
    // read the graph a write the offsets
61
    let mut offset = 0;
30✔
62
    let mut degs_iter = seq_graph.offset_deg_iter();
45✔
63
    for (new_offset, _degree) in &mut degs_iter {
9,766,725✔
64
        // write where
65
        writer
4,883,355✔
66
            .write_gamma((new_offset - offset) as _)
9,766,710✔
67
            .context("Could not write gamma")?;
68
        offset = new_offset;
4,883,355✔
69
        // decode the next nodes so we know where the next node_id starts
70
        pl.light_update();
9,766,710✔
71
    }
72
    // write the last offset, this is done to avoid decoding the last node
73
    writer
15✔
74
        .write_gamma((degs_iter.get_pos() - offset) as _)
45✔
75
        .context("Could not write final gamma")?;
76
    pl.light_update();
30✔
77
    pl.done();
30✔
78
    Ok(())
15✔
79
}
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