Skip to content

Commit

Permalink
Mark many inherent method inline
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerollmops committed Jan 7, 2025
1 parent fcb7dfb commit 245d604
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions roaring/src/bitmap/inherent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ impl RoaringBitmap {
/// Creates a new container if it doesn't exist.
///
/// Return the index of the target container.
#[inline]
fn find_container_by_key(&mut self, key: u16) -> usize {
match self.containers.binary_search_by_key(&key, |c| c.key) {
Ok(loc) => loc,
Expand Down Expand Up @@ -139,6 +140,7 @@ impl RoaringBitmap {
/// assert!(rb.contains(3));
/// assert!(!rb.contains(4));
/// ```
#[inline]
pub fn insert_range<R>(&mut self, range: R) -> u64
where
R: RangeBounds<u32>,
Expand Down Expand Up @@ -203,6 +205,7 @@ impl RoaringBitmap {
///
/// assert_eq!(rb.iter().collect::<Vec<u32>>(), vec![1, 3, 5]);
/// ```
#[inline]
pub fn push(&mut self, value: u32) -> bool {
let (key, index) = util::split(value);

Expand All @@ -225,6 +228,7 @@ impl RoaringBitmap {
/// # Panics
///
/// If debug_assertions enabled and index is > self.max()
#[inline]
pub(crate) fn push_unchecked(&mut self, value: u32) {
let (key, index) = util::split(value);

Expand Down Expand Up @@ -254,6 +258,7 @@ impl RoaringBitmap {
/// assert_eq!(rb.remove(3), false);
/// assert_eq!(rb.contains(3), false);
/// ```
#[inline]
pub fn remove(&mut self, value: u32) -> bool {
let (key, index) = util::split(value);
match self.containers.binary_search_by_key(&key, |c| c.key) {
Expand Down Expand Up @@ -284,6 +289,7 @@ impl RoaringBitmap {
/// rb.insert(3);
/// assert_eq!(rb.remove_range(2..4), 2);
/// ```
#[inline]
pub fn remove_range<R>(&mut self, range: R) -> u64
where
R: RangeBounds<u32>,
Expand Down Expand Up @@ -327,6 +333,7 @@ impl RoaringBitmap {
/// assert_eq!(rb.contains(1), true);
/// assert_eq!(rb.contains(100), false);
/// ```
#[inline]
pub fn contains(&self, value: u32) -> bool {
let (key, index) = util::split(value);
match self.containers.binary_search_by_key(&key, |c| c.key) {
Expand Down Expand Up @@ -354,6 +361,7 @@ impl RoaringBitmap {
/// // 0xFFF is not contained
/// assert!(!rb.contains_range(1..=0xFFF));
/// ```
#[inline]
pub fn contains_range<R>(&self, range: R) -> bool
where
R: RangeBounds<u32>,
Expand Down Expand Up @@ -414,6 +422,7 @@ impl RoaringBitmap {
/// assert_eq!(rb.range_cardinality(0x10000..0x10000), 0);
/// assert_eq!(rb.range_cardinality(0x50000..=u32::MAX), 3);
/// ```
#[inline]
pub fn range_cardinality<R>(&self, range: R) -> u64
where
R: RangeBounds<u32>,
Expand Down Expand Up @@ -473,6 +482,7 @@ impl RoaringBitmap {
/// rb.clear();
/// assert_eq!(rb.contains(1), false);
/// ```
#[inline]
pub fn clear(&mut self) {
self.containers.clear();
}
Expand All @@ -490,6 +500,7 @@ impl RoaringBitmap {
/// rb.insert(3);
/// assert_eq!(rb.is_empty(), false);
/// ```
#[inline]
pub fn is_empty(&self) -> bool {
self.containers.is_empty()
}
Expand All @@ -505,6 +516,7 @@ impl RoaringBitmap {
/// assert!(!rb.is_empty());
/// assert!(rb.is_full());
/// ```
#[inline]
pub fn is_full(&self) -> bool {
self.containers.len() == (u16::MAX as usize + 1)
&& self.containers.iter().all(Container::is_full)
Expand All @@ -527,6 +539,7 @@ impl RoaringBitmap {
/// rb.insert(4);
/// assert_eq!(rb.len(), 2);
/// ```
#[inline]
pub fn len(&self) -> u64 {
self.containers.iter().map(|container| container.len()).sum()
}
Expand All @@ -545,6 +558,7 @@ impl RoaringBitmap {
/// rb.insert(4);
/// assert_eq!(rb.min(), Some(3));
/// ```
#[inline]
pub fn min(&self) -> Option<u32> {
self.containers.first().and_then(|tail| tail.min().map(|min| util::join(tail.key, min)))
}
Expand Down Expand Up @@ -583,6 +597,7 @@ impl RoaringBitmap {
/// assert_eq!(rb.rank(3), 1);
/// assert_eq!(rb.rank(10), 2)
/// ```
#[inline]
pub fn rank(&self, value: u32) -> u64 {
// if len becomes cached for RoaringBitmap: return len if len > value

Expand Down Expand Up @@ -617,6 +632,7 @@ impl RoaringBitmap {
/// assert_eq!(rb.select(2), Some(100));
/// assert_eq!(rb.select(3), None);
/// ```
#[inline]
pub fn select(&self, n: u32) -> Option<u32> {
let mut n = n as u64;

Expand Down Expand Up @@ -648,6 +664,7 @@ impl RoaringBitmap {
/// let mut rb = RoaringBitmap::from_iter([1, 3, 7, 9]);
/// rb.remove_smallest(2);
/// assert_eq!(rb, RoaringBitmap::from_iter([7, 9]));
#[inline]
pub fn remove_smallest(&mut self, mut n: u64) {
// remove containers up to the front of the target
let position = self.containers.iter().position(|container| {
Expand Down Expand Up @@ -682,6 +699,7 @@ impl RoaringBitmap {
/// assert_eq!(rb, RoaringBitmap::from_iter([1, 5]));
/// rb.remove_biggest(1);
/// assert_eq!(rb, RoaringBitmap::from_iter([1]));
#[inline]
pub fn remove_biggest(&mut self, mut n: u64) {
// remove containers up to the back of the target
let position = self.containers.iter().rposition(|container| {
Expand Down

0 comments on commit 245d604

Please sign in to comment.