algorithm

Struct RoaringBitMap

Source
pub struct RoaringBitMap { /* private fields */ }
Expand description

位图类RoaringBitMap,根据访问的位看是否被占用 本质上是将大块的bitmap分成各个小块,其中每个小块在需要存储数据的时候才会存在 解决经典的是否被占用的问题,不会一次性分配大内存 头部以val / 65536做为索引键值, 尾部分为Array及HashSet结构 当元素个数小于4096时以有序array做为索引, 当>4096以HashSet做为存储

§Examples

use algorithm::RoaringBitMap;
fn main() {
    let mut map = RoaringBitMap::new();
    map.add_many(&vec![1, 2, 3, 4, 10]);
    assert!(map.contains(&1));
    assert!(!map.contains(&5));
    assert!(map.contains(&10));
    map.add_range(7, 16);
    assert!(!map.contains(&6));
    assert!(map.contains(&7));
    assert!(map.contains(&16));
    assert!(!map.contains(&17));
}

Implementations§

Source§

impl RoaringBitMap

Source

pub fn new() -> Self

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn clear(&mut self)

Source

pub fn add(&mut self, val: usize)

添加新的元素

§Examples
use algorithm::RoaringBitMap;
fn main() {
    let mut map = RoaringBitMap::new();
    map.add(1);
    assert!(map.contains(&1));
    assert!(map.len() == 1);
}
Source

pub fn add_many(&mut self, val: &[usize])

添加许多新的元素

§Examples
use algorithm::RoaringBitMap;
fn main() {
    let mut map = RoaringBitMap::new();
    map.add_many(&vec![1, 2, 3, 4, 10]);
    assert!(map.contains(&1));
    assert!(map.contains(&10));
    assert!(map.len() == 5);
}
Source

pub fn add_range(&mut self, start: usize, end: usize)

添加范围内的元素(包含头与结果),批量添加增加效率

§Examples
use algorithm::RoaringBitMap;
fn main() {
    let mut map = RoaringBitMap::new();
    map.add_range(7, 16);
    assert!(!map.contains(&6));
    assert!(map.contains(&7));
    assert!(map.contains(&16));
    assert!(!map.contains(&17));
    assert!(map.len() == 10);
}
Source

pub fn remove(&mut self, val: usize) -> bool

删除元素

§Examples
use algorithm::RoaringBitMap;
fn main() {
    let mut map = RoaringBitMap::new();
    map.add_range(7, 16);
    assert!(map.len() == 10);
    assert!(map.contains(&7));
    assert!(map.remove(7));
    assert!(!map.contains(&7));
    assert!(map.len() == 9);
}
Source

pub fn remove_many(&mut self, val: &[usize])

删除列表中元素

§Examples
use algorithm::RoaringBitMap;
fn main() {
    let mut map = RoaringBitMap::new();
    map.add_range(7, 16);
    assert!(map.len() == 10);
    assert!(map.contains(&7));
    assert!(map.remove(7));
    assert!(!map.contains(&7));
    assert!(map.len() == 9);
}
Source

pub fn remove_range(&mut self, start: usize, end: usize)

删除范围元素(包含头与尾)

§Examples
use algorithm::RoaringBitMap;
fn main() {
    let mut map = RoaringBitMap::new();
    map.add_range(7, 16);
    assert!(map.len() == 10);
    map.remove_range(7, 15);
    assert!(map.len() == 1);
    assert!(map.contains(&16));
}
Source

pub fn contains(&self, val: &usize) -> bool

醒看是否包含

§Examples
use algorithm::RoaringBitMap;
fn main() {
    let mut map = RoaringBitMap::new();
    map.add(7);
    assert!(map.contains(&7));
}
Source

pub fn iter(&self) -> Iter<'_>

迭代器,通过遍历进行循环,如果位图的容量非常大,可能效率相当低

§Examples
use algorithm::RoaringBitMap;
fn main() {
    let mut map = RoaringBitMap::new();
    map.add(7);
    map.add_range(9, 12);
    map.add_many(&vec![20, 100, 300]);
    assert!(map.iter().collect::<Vec<_>>() == vec![7, 9, 10, 11, 12, 20, 100, 300]);
}
Source

pub fn retain<F>(&mut self, f: F)
where F: FnMut(&usize) -> bool,

是否保留,通过遍历进行循环,如果位图的容量非常大,可能效率相当低

§Examples
use algorithm::RoaringBitMap;
fn main() {
    let mut map = RoaringBitMap::new();
    map.add_range(9, 16);
    map.retain(|v| v % 2 == 0);
    assert!(map.iter().collect::<Vec<_>>() == vec![10, 12, 14, 16]);
}
Source

pub fn contains_sub(&self, other: &RoaringBitMap) -> bool

是否为子位图

§Examples
use algorithm::RoaringBitMap;
fn main() {
    let mut map = RoaringBitMap::new();
    map.add_range(9, 16);
    let mut sub_map = RoaringBitMap::new();
    sub_map.add_range(9, 12);
    assert!(map.contains_sub(&sub_map));
}
Source

pub fn intersect(&self, other: &RoaringBitMap) -> RoaringBitMap

取两个位图间的交集

§Examples
use algorithm::RoaringBitMap;
fn main() {
    let mut map = RoaringBitMap::new();
    map.add_range(9, 16);
    let mut sub_map = RoaringBitMap::new();
    sub_map.add_range(7, 12);
    let map = map.intersect(&sub_map);
    assert!(map.iter().collect::<Vec<_>>() == vec![9, 10, 11, 12]);
}
Source

pub fn union(&self, other: &RoaringBitMap) -> RoaringBitMap

取两个位图间的并集

§Examples
use algorithm::RoaringBitMap;
fn main() {
    let mut map = RoaringBitMap::new();
    map.add_range(9, 16);
    let mut sub_map = RoaringBitMap::new();
    sub_map.add_range(7, 12);
    let map = map.union(&sub_map);
    assert!(map.iter().collect::<Vec<_>>() == vec![7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
}
Source

pub fn union_xor(&self, other: &RoaringBitMap) -> RoaringBitMap

取两个位图间的异或并集

§Examples
use algorithm::RoaringBitMap;
fn main() {
    let mut map = RoaringBitMap::new();
    map.add_range(9, 16);
    let mut sub_map = RoaringBitMap::new();
    sub_map.add_range(7, 12);
    let map = map.union_xor(&sub_map);
    assert!(map.iter().collect::<Vec<_>>() == vec![7, 8, 13, 14, 15, 16]);
}

Trait Implementations§

Source§

impl BitAnd for &RoaringBitMap

Source§

type Output = RoaringBitMap

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: Self) -> Self::Output

Performs the & operation. Read more
Source§

impl BitOr for &RoaringBitMap

Source§

type Output = RoaringBitMap

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: Self) -> Self::Output

Performs the | operation. Read more
Source§

impl BitXor for &RoaringBitMap

Source§

type Output = RoaringBitMap

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: Self) -> Self::Output

Performs the ^ operation. Read more
Source§

impl Clone for RoaringBitMap

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RoaringBitMap

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for RoaringBitMap

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Extend<usize> for RoaringBitMap

Source§

fn extend<T: IntoIterator<Item = usize>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl FromIterator<usize> for RoaringBitMap

Source§

fn from_iter<T: IntoIterator<Item = usize>>(iter: T) -> RoaringBitMap

Creates a value from an iterator. Read more
Source§

impl PartialEq for RoaringBitMap

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for RoaringBitMap

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.