Coverage Report

Created: 2025-11-28 06:44

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/roaring-0.11.2/src/lib.rs
Line
Count
Source
1
//! This is a [Rust][] port of the [Roaring bitmap][] data structure, initially
2
//! defined as a [Java library][roaring-java] and described in [_Better bitmap
3
//! performance with Roaring bitmaps_][roaring-paper].
4
//!
5
//! [Rust]: https://www.rust-lang.org/
6
//! [Roaring bitmap]: https://roaringbitmap.org/
7
//! [roaring-java]: https://github.com/lemire/RoaringBitmap
8
//! [roaring-paper]: https://arxiv.org/pdf/1402.6407v4
9
10
#![cfg_attr(not(feature = "std"), no_std)]
11
#![cfg_attr(feature = "simd", feature(portable_simd))]
12
#![warn(missing_docs)]
13
#![warn(unsafe_op_in_unsafe_fn)]
14
#![warn(variant_size_differences)]
15
#![allow(unknown_lints)] // For clippy
16
#![allow(clippy::doc_overindented_list_items)]
17
#![deny(unnameable_types)]
18
19
#[cfg(feature = "std")]
20
extern crate byteorder;
21
22
#[macro_use]
23
extern crate alloc;
24
25
use core::fmt;
26
27
/// A compressed bitmap using the [Roaring bitmap compression scheme](https://roaringbitmap.org/).
28
pub mod bitmap;
29
30
/// A compressed bitmap with u64 values.  Implemented as a `BTreeMap` of `RoaringBitmap`s.
31
pub mod treemap;
32
33
pub use bitmap::RoaringBitmap;
34
pub use treemap::RoaringTreemap;
35
36
/// An error type that is returned when a `try_push` in a bitmap did not succeed.
37
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
38
pub struct IntegerTooSmall;
39
40
impl fmt::Display for IntegerTooSmall {
41
0
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
42
0
        f.write_str("inserted integer is smaller than the largest integer")
43
0
    }
44
}
45
46
/// An error type that is returned when an iterator isn't sorted.
47
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
48
pub struct NonSortedIntegers {
49
    valid_until: u64,
50
}
51
52
impl NonSortedIntegers {
53
    /// Returns the number of elements that were
54
0
    pub fn valid_until(&self) -> u64 {
55
0
        self.valid_until
56
0
    }
57
}
58
59
impl fmt::Display for NonSortedIntegers {
60
0
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
61
0
        write!(f, "integers are ordered up to the {}th element", self.valid_until())
62
0
    }
63
}
64
65
#[cfg(feature = "std")]
66
impl std::error::Error for NonSortedIntegers {}
67
68
/// A [`Iterator::collect`] blanket implementation that provides extra methods for [`RoaringBitmap`]
69
/// and [`RoaringTreemap`].
70
///
71
/// When merging multiple bitmap with the same operation it's usually faster to call the
72
/// method in this trait than to write your own for loop and merging the bitmaps yourself.
73
///
74
/// # Examples
75
/// ```
76
/// use roaring::{MultiOps, RoaringBitmap};
77
///
78
/// let bitmaps = [
79
///     RoaringBitmap::from_iter(0..10),
80
///     RoaringBitmap::from_iter(10..20),
81
///     RoaringBitmap::from_iter(20..30),
82
/// ];
83
///
84
/// // Stop doing this
85
/// let naive = bitmaps.clone().into_iter().reduce(|a, b| a | b).unwrap_or_default();
86
///
87
/// // And start doing this instead, it will be much faster!
88
/// let iter = bitmaps.union();
89
///
90
/// assert_eq!(naive, iter);
91
/// ```
92
pub trait MultiOps<T>: IntoIterator<Item = T> {
93
    /// The type of output from operations.
94
    type Output;
95
96
    /// The `union` between all elements.
97
    fn union(self) -> Self::Output;
98
99
    /// The `intersection` between all elements.
100
    fn intersection(self) -> Self::Output;
101
102
    /// The `difference` between all elements.
103
    fn difference(self) -> Self::Output;
104
105
    /// The `symmetric difference` between all elements.
106
    fn symmetric_difference(self) -> Self::Output;
107
}