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

vigna / webgraph-rs / 14130263389

28 Mar 2025 01:40PM UTC coverage: 49.654% (-0.1%) from 49.798%
14130263389

push

github

zommiommy
fixed llp wrong combine types

22 of 41 new or added lines in 4 files covered. (53.66%)

1019 existing lines in 41 files now uncovered.

2437 of 4908 relevant lines covered (49.65%)

18919274.03 hits per line

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

26.47
/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

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

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

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

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

70
impl BitFieldSliceCore<usize> for JavaPermutation {
71
    fn bit_width(&self) -> usize {
×
72
        64
×
73
    }
74

75
    fn len(&self) -> usize {
24,180,278✔
76
        self.perm.as_ref().len()
24,180,278✔
77
    }
78
}
79

80
impl BitFieldSliceCore<usize> for JavaPermutation<MmapHelper<u64, MmapMut>> {
81
    fn bit_width(&self) -> usize {
×
82
        64
×
83
    }
84

85
    fn len(&self) -> usize {
×
86
        self.perm.as_ref().len()
×
87
    }
88
}
89

90
impl BitFieldSlice<usize> for JavaPermutation {
91
    #[inline(always)]
92
    unsafe fn get_unchecked(&self, index: usize) -> usize {
24,180,276✔
93
        u64::from_be_bytes(self.perm.as_ref().get_unchecked(index).to_ne_bytes()) as usize
24,180,276✔
94
    }
95
}
96

97
impl BitFieldSlice<usize> for JavaPermutation<MmapHelper<u64, MmapMut>> {
98
    #[inline(always)]
99
    unsafe fn get_unchecked(&self, index: usize) -> usize {
×
100
        u64::from_be_bytes(self.perm.as_ref().get_unchecked(index).to_ne_bytes()) as usize
×
101
    }
102
}
103

104
impl BitFieldSliceMut<usize> for JavaPermutation<MmapHelper<u64, MmapMut>> {
105
    #[inline(always)]
106
    unsafe fn set_unchecked(&mut self, index: usize, value: usize) {
×
107
        *self.perm.as_mut().get_unchecked_mut(index) = value as u64;
×
108
    }
109

110
    #[inline(always)]
111
    fn reset(&mut self) {
×
112
        self.perm.as_mut().reset();
×
113
    }
114

UNCOV
115
    fn par_reset(&mut self) {
×
UNCOV
116
        self.perm.as_mut().par_reset();
×
117
    }
118

UNCOV
119
    fn as_mut_slice(&mut self) -> &mut [usize] {
×
120
        unimplemented!(
121
            "This method is not implemented for JavaPermutation<MmapHelper<u64, MmapMut>>"
122
        );
123
    }
124

125
    type ChunksMut<'a>
126
        = std::slice::ChunksMut<'a, usize>
127
    where
128
        Self: 'a;
129

UNCOV
130
    fn try_chunks_mut(&mut self, _chunk_size: usize) -> Result<Self::ChunksMut<'_>, ()> {
×
131
        // Unsupported
UNCOV
132
        Err(())
×
133
    }
134
}
135

136
impl AsRef<[u64]> for JavaPermutation {
137
    fn as_ref(&self) -> &[u64] {
10✔
138
        self.perm.as_ref()
10✔
139
    }
140
}
141

142
impl AsRef<[u64]> for JavaPermutation<MmapHelper<u64, MmapMut>> {
UNCOV
143
    fn as_ref(&self) -> &[u64] {
×
UNCOV
144
        self.perm.as_ref()
×
145
    }
146
}
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