Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions roaring/src/bitmap/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub(crate) struct Iter<'a> {
}

impl Container {
pub fn new(key: u16) -> Container {
pub const fn new(key: u16) -> Container {
Container { key, store: Store::new() }
}

Expand Down Expand Up @@ -61,7 +61,7 @@ impl Container {
self.store.len()
}

pub fn is_empty(&self) -> bool {
pub const fn is_empty(&self) -> bool {
self.store.is_empty()
}

Expand Down
4 changes: 2 additions & 2 deletions roaring/src/bitmap/inherent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl RoaringBitmap {
/// use roaring::RoaringBitmap;
/// let rb = RoaringBitmap::new();
/// ```
pub fn new() -> RoaringBitmap {
pub const fn new() -> RoaringBitmap {
RoaringBitmap { containers: Vec::new() }
}

Expand Down Expand Up @@ -635,7 +635,7 @@ impl RoaringBitmap {
/// assert_eq!(rb.is_empty(), false);
/// ```
#[inline]
pub fn is_empty(&self) -> bool {
pub const fn is_empty(&self) -> bool {
self.containers.is_empty()
}

Expand Down
2 changes: 1 addition & 1 deletion roaring/src/bitmap/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ impl RoaringBitmap {
}
}

fn header_size(size: usize, has_run_containers: bool) -> usize {
const fn header_size(size: usize, has_run_containers: bool) -> usize {
if has_run_containers {
// New format encodes the size (number of containers) into the 4 byte cookie
// Additionally a bitmap is included marking which containers are run containers
Expand Down
12 changes: 6 additions & 6 deletions roaring/src/bitmap/store/array_store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ fn intersect(lhs: &[u16], rhs: &[u16], visitor: &mut impl BinaryOperationVisitor
}

impl ArrayStore {
pub fn new() -> ArrayStore {
pub const fn new() -> ArrayStore {
ArrayStore { vec: vec![] }
}

pub fn serialized_byte_size(cardinality: u64) -> usize {
pub const fn serialized_byte_size(cardinality: u64) -> usize {
cardinality as usize * ARRAY_ELEMENT_BYTES
}

pub fn byte_size(&self) -> usize {
pub const fn byte_size(&self) -> usize {
Self::serialized_byte_size(self.len())
}

Expand All @@ -97,7 +97,7 @@ impl ArrayStore {
}

/// The number of total values that can be inserted without needing to reallocate.
pub fn capacity(&self) -> usize {
pub const fn capacity(&self) -> usize {
self.vec.capacity()
}

Expand Down Expand Up @@ -300,11 +300,11 @@ impl ArrayStore {
BitmapStore::from_unchecked(len, bits)
}

pub fn len(&self) -> u64 {
pub const fn len(&self) -> u64 {
self.vec.len() as u64
}

pub fn is_empty(&self) -> bool {
pub const fn is_empty(&self) -> bool {
self.vec.is_empty()
}

Expand Down
8 changes: 8 additions & 0 deletions roaring/src/bitmap/store/array_store/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ const LANES: usize = 8;
/// With `std`, this is detected at runtime on x86/x86-64 (and cached by `fearless_simd`).
/// Otherwise, it is determined by the target features enabled at compile time.
#[inline]
// Scoped to `not(std)`, the only config where the lint fires; a plain `expect` would go unfulfilled.
#[cfg_attr(
not(feature = "std"),
expect(
clippy::missing_const_for_fn,
reason = "`Level::new()` under `std` is runtime detection"
)
)]
fn level() -> Level {
#[cfg(feature = "std")]
return Level::new();
Expand Down
4 changes: 2 additions & 2 deletions roaring/src/bitmap/store/array_store/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ pub struct CardinalityCounter {
}

impl CardinalityCounter {
pub fn new() -> CardinalityCounter {
pub const fn new() -> CardinalityCounter {
CardinalityCounter { count: 0 }
}

pub fn into_inner(self) -> u64 {
pub const fn into_inner(self) -> u64 {
self.count as u64
}
}
Expand Down
10 changes: 5 additions & 5 deletions roaring/src/bitmap/store/bitmap_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl BitmapStore {
BitmapStore { len: 0, bits: Box::new([0; BITMAP_LENGTH]) }
}

pub fn capacity(&self) -> usize {
pub const fn capacity(&self) -> usize {
BITMAP_LENGTH * u64::BITS as usize
}

Expand Down Expand Up @@ -282,11 +282,11 @@ impl BitmapStore {
ArrayStore::from_vec_unchecked(vec)
}

pub fn len(&self) -> u64 {
pub const fn len(&self) -> u64 {
self.len
}

pub fn is_empty(&self) -> bool {
pub const fn is_empty(&self) -> bool {
self.len == 0
}

Expand Down Expand Up @@ -834,12 +834,12 @@ impl<B: Borrow<[u64; BITMAP_LENGTH]>> DoubleEndedIterator for BitmapIter<B> {
impl<B: Borrow<[u64; BITMAP_LENGTH]>> ExactSizeIterator for BitmapIter<B> {}

#[inline]
pub fn key(index: u16) -> usize {
pub const fn key(index: u16) -> usize {
index as usize / 64
}

#[inline]
pub fn bit(index: u16) -> usize {
pub const fn bit(index: u16) -> usize {
index as usize % 64
}

Expand Down
20 changes: 10 additions & 10 deletions roaring/src/bitmap/store/interval_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ impl IntervalStore {
Self(alloc::vec![Interval::new_unchecked(0, u16::MAX)])
}

pub fn byte_size(&self) -> usize {
pub const fn byte_size(&self) -> usize {
Self::serialized_byte_size(self.run_amount())
}

pub fn serialized_byte_size(run_amount: u64) -> usize {
pub const fn serialized_byte_size(run_amount: u64) -> usize {
RUN_NUM_BYTES + (RUN_ELEMENT_BYTES * run_amount as usize)
}

Expand Down Expand Up @@ -446,7 +446,7 @@ impl IntervalStore {
self.0.iter().map(|iv| iv.run_len()).sum()
}

pub fn is_empty(&self) -> bool {
pub const fn is_empty(&self) -> bool {
self.0.is_empty()
}

Expand Down Expand Up @@ -485,7 +485,7 @@ impl IntervalStore {
None
}

pub fn run_amount(&self) -> u64 {
pub const fn run_amount(&self) -> u64 {
self.0.len() as u64
}

Expand Down Expand Up @@ -678,7 +678,7 @@ pub(crate) struct RunIter<I: SliceIterator<Interval>> {
}

impl<I: SliceIterator<Interval>> RunIter<I> {
fn new(intervals: I) -> Self {
const fn new(intervals: I) -> Self {
Self { forward_offset: 0, backward_offset: 0, intervals }
}

Expand Down Expand Up @@ -956,7 +956,7 @@ impl IntoIterator for &'_ Interval {
}
}

pub(crate) fn cmp_index_interval(index: u16, iv: Interval) -> Ordering {
pub(crate) const fn cmp_index_interval(index: u16, iv: Interval) -> Ordering {
if index < iv.start {
Ordering::Less
} else if index > iv.end {
Expand All @@ -972,15 +972,15 @@ impl Interval {
Self { start, end }
}

pub fn start(&self) -> u16 {
pub const fn start(&self) -> u16 {
self.start
}

pub fn end(&self) -> u16 {
pub const fn end(&self) -> u16 {
self.end
}

pub fn overlaps(&self, interval: &Self) -> bool {
pub const fn overlaps(&self, interval: &Self) -> bool {
interval.start <= self.end && self.start <= interval.end
}

Expand All @@ -996,7 +996,7 @@ impl Interval {
u64::from(self.end - self.start) + 1
}

pub fn is_full(&self) -> bool {
pub const fn is_full(&self) -> bool {
self.start == 0 && self.end == u16::MAX
}
}
Expand Down
4 changes: 2 additions & 2 deletions roaring/src/bitmap/store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub(crate) enum Iter<'a> {
}

impl Store {
pub fn new() -> Store {
pub const fn new() -> Store {
Store::Array(ArrayStore::new())
}

Expand Down Expand Up @@ -257,7 +257,7 @@ impl Store {
}
}

pub fn is_empty(&self) -> bool {
pub const fn is_empty(&self) -> bool {
match self {
Array(vec) => vec.is_empty(),
Bitmap(bits) => bits.is_empty(),
Expand Down
2 changes: 1 addition & 1 deletion roaring/src/bitmap/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use core::ops::{Bound, RangeBounds, RangeInclusive};
/// Returns the container key and the index
/// in this container for a given integer.
#[inline]
pub fn split(value: u32) -> (u16, u16) {
pub const fn split(value: u32) -> (u16, u16) {
((value >> 16) as u16, value as u16)
}

Expand Down
2 changes: 1 addition & 1 deletion roaring/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub struct NonSortedIntegers {

impl NonSortedIntegers {
/// Returns the number of elements that were
pub fn valid_until(&self) -> u64 {
pub const fn valid_until(&self) -> u64 {
self.valid_until
}
}
Expand Down
2 changes: 1 addition & 1 deletion roaring/src/treemap/inherent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl RoaringTreemap {
/// use roaring::RoaringTreemap;
/// let rb = RoaringTreemap::new();
/// ```
pub fn new() -> RoaringTreemap {
pub const fn new() -> RoaringTreemap {
RoaringTreemap { map: BTreeMap::new() }
}

Expand Down
2 changes: 1 addition & 1 deletion roaring/src/treemap/util.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use core::ops::{Bound, RangeBounds, RangeInclusive};

#[inline]
pub fn split(value: u64) -> (u32, u32) {
pub const fn split(value: u64) -> (u32, u32) {
((value >> 32) as u32, value as u32)
}

Expand Down
Loading