Skip to content

Commit 2640c9a

Browse files
committed
Add docs
1 parent 3bbeb3e commit 2640c9a

File tree

7 files changed

+32
-8
lines changed

7 files changed

+32
-8
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "mmap-bitvec"
33
version = "0.4.0"
44
authors = ["Roderick Bovee <roderick@onecodex.com>"]
55
autobenches = false
6-
edition = "2018"
6+
edition = "2021"
77

88
[dependencies]
99
memmap2 = "0.5"

benches/benchmark.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ fn get_range_simplified(mmap: &MmapMut, size: usize, l: usize) -> BitVecSlice {
6363

6464
fn get_range(mmap: &MmapMut, size: usize, r: Range<usize>) -> BitVecSlice {
6565
if r.end - r.start > BIT_VEC_SLICE_SIZE as usize {
66-
panic!(format!("Range too large (>{})", BIT_VEC_SLICE_SIZE))
66+
panic!("Range too large (>{})", BIT_VEC_SLICE_SIZE)
6767
} else if r.end > size {
6868
panic!("Range ends outside of BitVec")
6969
}

src/bitvec.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
use std::ops::Range;
22

3+
/// A nasic bitvector trait that we implement for mmap
34
pub trait BitVector {
5+
/// Get the value at bit `i`
46
fn get(&self, i: usize) -> bool;
7+
/// Set the value at bit `i`
58
fn set(&mut self, i: usize, x: bool);
9+
/// Returns the size of the bitvector
610
fn size(&self) -> usize;
711

12+
/// Returns the number of bits sets in the given range
813
fn rank(&self, r: Range<usize>) -> usize {
914
r.fold(0, |a, x| a + if self.get(x) { 1 } else { 0 })
1015
}
1116

17+
/// Returns the position of the n-th bit set
1218
fn select(&self, n: usize, start: usize) -> Option<usize> {
1319
let mut bits_left = n;
1420

@@ -24,6 +30,7 @@ pub trait BitVector {
2430
None
2531
}
2632

33+
/// Return all the bits in the given range as a u128
2734
fn get_range(&self, r: Range<usize>) -> u128 {
2835
if r.end - r.start > 128 {
2936
panic!("Range too large (>128)")
@@ -42,6 +49,7 @@ pub trait BitVector {
4249
bvs
4350
}
4451

52+
/// Sets all the bits in the given range from the given u128
4553
fn set_range(&mut self, r: Range<usize>, x: u128) {
4654
let mut cur = x;
4755
for i in r.rev() {
@@ -50,6 +58,7 @@ pub trait BitVector {
5058
}
5159
}
5260

61+
/// Sets all the bit in the given range to false
5362
fn clear_range(&mut self, r: Range<usize>) {
5463
for i in r.rev() {
5564
self.set(i, false);
@@ -128,5 +137,3 @@ impl BitVector for Vec<u8> {
128137
self.len() / 8
129138
}
130139
}
131-
132-
// TODO: impl for `bv::BitVec` and `bit-vec::BitVec`?

src/bloom.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,18 @@ use murmurhash3::murmurhash3_x64_128;
77
use crate::bitvec::BitVector;
88
use crate::mmap_bitvec::MmapBitVec;
99

10-
// we don't want to use murmurhash3::Murmur3Hasher b/c it makes copies of the
11-
// bytes to be hashed with every single `hash` call
10+
/// Newtype for murmur hashing
11+
/// we don't want to use murmurhash3::Murmur3Hasher b/c it makes copies of the
12+
/// bytes to be hashed with every single `hash` call
1213
#[derive(Default)]
1314
pub struct MurmurHasher(u64, u64);
1415

1516
impl MurmurHasher {
17+
#[allow(missing_docs)]
1618
pub fn new() -> Self {
1719
MurmurHasher(0, 0)
1820
}
19-
21+
#[allow(missing_docs)]
2022
pub fn values(&self) -> (u64, u64) {
2123
(self.0, self.1)
2224
}

src/combinatorial.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ static MARKER_TABLES: Lazy<HashMap<u8, Vec<u128>>> = Lazy::new(|| {
2727
m
2828
});
2929

30+
/// https://en.wikipedia.org/wiki/Combinatorial_number_system
3031
pub fn rank(value: usize, k: u8) -> u128 {
3132
assert!(k > 0 && k < 10, "kappa needs to be less than 10");
3233
// it's possible this may overflow if value > (128 choose k) or return
@@ -42,6 +43,7 @@ pub fn rank(value: usize, k: u8) -> u128 {
4243
}
4344
}
4445

46+
/// https://en.wikipedia.org/wiki/Combinatorial_number_system
4547
pub fn unrank(marker: u128) -> usize {
4648
// val = choose(rank(0), 1) + choose(rank(1), 2) + choose(rank(2), 3) + ...
4749
let mut working_marker = marker;

src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1+
#![deny(missing_docs)]
2+
13
//! mmap-bitvec is a library for using file-backed (via mmap) bit vectors and
24
//! includes common convenience functions and a few data structures built atop
35
//! the included bit vector implementation.
46
7+
/// The bitvec trait and some impl for built-in types
58
pub mod bitvec;
9+
/// A simple implementation of a Bloom filter backed by `BitVec`
610
pub mod bloom;
11+
/// Some combinatorial utilities
712
pub mod combinatorial;
13+
/// All the utilities to interact with a mmapped bitvector
814
pub mod mmap_bitvec;
915

1016
#[doc(inline)]

src/mmap_bitvec.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@ use crate::bitvec::BitVector;
1212
/// Really annoying we have to mock over both of these rather than memmap
1313
/// just providing support.
1414
pub enum CommonMmap {
15+
/// A mutable mmap
1516
MmapMut(MmapMut),
17+
/// A read-only mmap
1618
Mmap(Mmap),
1719
}
1820

1921
impl CommonMmap {
22+
/// Get a non-mutable pointer to the mmap
2023
#[inline]
2124
pub fn as_ptr(&self) -> *const u8 {
2225
match self {
@@ -25,6 +28,7 @@ impl CommonMmap {
2528
}
2629
}
2730

31+
/// Get a mutable pointer to the mmap
2832
#[inline]
2933
pub fn as_mut_ptr(&mut self) -> *mut u8 {
3034
// maybe we should override the original type signature and return
@@ -35,6 +39,7 @@ impl CommonMmap {
3539
}
3640
}
3741

42+
/// Flush to disk. A no-op if the mmap is read-only
3843
#[inline]
3944
pub fn flush(&mut self) -> Result<(), io::Error> {
4045
match self {
@@ -56,7 +61,9 @@ impl CommonMmap {
5661
/// assert_eq!(bv.get_range(2..12), 0b1001101101);
5762
/// ```
5863
pub struct MmapBitVec {
64+
/// The mmap we are using, either a mutable or read-only one
5965
pub mmap: CommonMmap,
66+
/// Number of bits in the bitvector
6067
pub size: usize,
6168
header: Box<[u8]>,
6269
is_anon: bool,
@@ -243,7 +250,7 @@ impl MmapBitVec {
243250
Ok(file_mmap)
244251
}
245252

246-
// Returns the header
253+
/// Returns the header
247254
pub fn header(&self) -> &[u8] {
248255
&self.header
249256
}

0 commit comments

Comments
 (0)