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

vigna / webgraph-rs / 19278972970

11 Nov 2025 09:25PM UTC coverage: 62.316% (+14.3%) from 48.052%
19278972970

push

github

zommiommy
BatchCodec print stats and encoding time

40 of 53 new or added lines in 4 files covered. (75.47%)

814 existing lines in 46 files now uncovered.

5252 of 8428 relevant lines covered (62.32%)

29580067.92 hits per line

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

30.0
/webgraph/src/utils/java_perm.rs
1
/*
2
 * SPDX-FileCopyrightText: 2023 Inria
3
 * SPDX-FileCopyrightText: 2024 Sebastiano Vigna
4
 *
5
 * SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
6
 */
7

8
use crate::utils::{ArcMmapHelper, MmapHelper};
9
use anyhow::Result;
10
use mmap_rs::{MmapFlags, MmapMut};
11
use std::path::Path;
12
use std::sync::Arc;
13
use sux::traits::*;
14
use value_traits::slices::{SliceByValue, SliceByValueMut};
15

16
/// Maps into memory a file of big-endian 64-bit values, making it accessible as
17
/// a [`BitFieldSlice<usize>`](sux::traits::BitFieldSlice).
18
///
19
/// The purpose of this helper class make interoperability with the big version
20
/// of the Java implementation of WebGraph easier. It is a thin wrapper
21
/// around [`MmapHelper`], and its methods are named accordingly.
22
///
23
/// Note that this class is only available on 64-bit platforms.
24
///
25
/// By default it uses an `Arc<Mmap>` so that it can be cloned.
26
#[cfg(target_pointer_width = "64")]
27
#[derive(Clone)]
28
pub struct JavaPermutation<M = ArcMmapHelper<u64>> {
29
    pub perm: M,
30
}
31

32
#[cfg(target_pointer_width = "64")]
33
impl JavaPermutation<MmapHelper<u64, MmapMut>> {
34
    /// Creates and map a permutation into memory (read/write), overwriting it if it exists.
35
    ///
36
    /// # Arguments
37
    /// - `path` - The path to the permutation.
38
    /// - `flags` - The flags to use for the memory mapping.
39
    /// - `len` - The length of the permutation (number of 64-bit unsigned values).
40
    pub fn new(path: impl AsRef<Path>, flags: MmapFlags, len: usize) -> Result<Self> {
×
41
        Ok(Self {
×
UNCOV
42
            perm: MmapHelper::new(path, flags, len)?,
×
43
        })
44
    }
45

46
    /// Maps a permutation into memory (read/write).
47
    ///
48
    /// # Arguments
49
    /// - `path` - The path to the permutation.
50
    /// - `flags` - The flags to use for the memory mapping.
51
    pub fn mmap_mut(path: impl AsRef<Path>, flags: MmapFlags) -> Result<Self> {
×
52
        Ok(Self {
×
UNCOV
53
            perm: MmapHelper::mmap_mut(path, flags)?,
×
54
        })
55
    }
56
}
57

58
impl JavaPermutation {
59
    /// Maps a permutation into memory (read-only).
60
    ///
61
    /// # Arguments
62
    /// - `path` - The path to the permutation.
63
    /// - `flags` - The flags to use for the memory mapping.
64
    pub fn mmap(path: impl AsRef<Path>, flags: MmapFlags) -> Result<Self> {
17✔
UNCOV
65
        Ok(Self {
×
66
            perm: ArcMmapHelper(Arc::new(MmapHelper::mmap(path, flags)?)),
68✔
67
        })
68
    }
69
}
70

71
impl BitWidth<usize> for JavaPermutation {
72
    fn bit_width(&self) -> usize {
×
UNCOV
73
        64
×
74
    }
75
}
76

77
impl BitWidth<usize> for JavaPermutation<MmapHelper<u64, MmapMut>> {
UNCOV
78
    fn bit_width(&self) -> usize {
×
UNCOV
79
        64
×
80
    }
81
}
82

83
impl SliceByValue for JavaPermutation {
84
    type Value = usize;
85
    fn len(&self) -> usize {
48,360,556✔
86
        self.perm.as_ref().len()
96,721,112✔
87
    }
88
    #[inline(always)]
89
    unsafe fn get_value_unchecked(&self, index: usize) -> usize {
48,360,552✔
90
        u64::from_be_bytes(unsafe { self.perm.as_ref().get_unchecked(index).to_ne_bytes() })
145,081,656✔
91
            as usize
48,360,552✔
92
    }
93
}
94

95
impl SliceByValue for JavaPermutation<MmapHelper<u64, MmapMut>> {
96
    type Value = usize;
UNCOV
97
    fn len(&self) -> usize {
×
UNCOV
98
        self.perm.as_ref().len()
×
99
    }
100
    #[inline(always)]
101
    unsafe fn get_value_unchecked(&self, index: usize) -> usize {
×
102
        u64::from_be_bytes(unsafe { self.perm.as_ref().get_unchecked(index).to_ne_bytes() })
×
UNCOV
103
            as usize
×
104
    }
105
}
106

107
impl SliceByValueMut for JavaPermutation<MmapHelper<u64, MmapMut>> {
108
    #[inline(always)]
UNCOV
109
    unsafe fn set_value_unchecked(&mut self, index: usize, value: usize) {
×
110
        unsafe {
UNCOV
111
            *self.perm.as_mut().get_unchecked_mut(index) = value as u64;
×
112
        }
113
    }
114

115
    type ChunksMut<'a>
116
        = std::slice::ChunksMut<'a, usize>
117
    where
118
        Self: 'a;
119

120
    type ChunksMutError = std::convert::Infallible;
121

UNCOV
122
    fn try_chunks_mut(
×
123
        &mut self,
124
        _chunk_size: usize,
125
    ) -> Result<Self::ChunksMut<'_>, std::convert::Infallible> {
126
        unimplemented!(
127
            "This method is not implemented for JavaPermutation<MmapHelper<u64, MmapMut>>"
128
        );
129
    }
130
}
131

132
impl AsRef<[u64]> for JavaPermutation {
133
    fn as_ref(&self) -> &[u64] {
20✔
134
        self.perm.as_ref()
20✔
135
    }
136
}
137

138
impl AsRef<[u64]> for JavaPermutation<MmapHelper<u64, MmapMut>> {
UNCOV
139
    fn as_ref(&self) -> &[u64] {
×
UNCOV
140
        self.perm.as_ref()
×
141
    }
142
}
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