Class: Roaring::Bitmap
- Inherits:
-
Object
- Object
- Roaring::Bitmap
- Includes:
- Enumerable
- Defined in:
- ext/roaring/src/lib.rs,
lib/roaring.rb
Overview
Roaring::Bitmap is a fast, compressed bitmap implementation.
Class Method Summary collapse
- ._load(args) ⇒ Object
-
.deserialize(rstr) ⇒ Roaring::Bitmap
Deserializes a bitmap from its binary representation.
-
.from_a(array) ⇒ Roaring::Bitmap
Initializes a new bitmap from an array of integers.
-
.full ⇒ Roaring::Bitmap
Initializes a new bitmap with all bits set to 1.
-
.new ⇒ Roaring::Bitmap
Initializes a new empty bitmap.
Instance Method Summary collapse
- #_dump(_level) ⇒ Object
-
#byte_size ⇒ Integer
Returns the size of the bitmap in bytes.
-
#cardinality ⇒ Integer
(also: #size, #count, #length)
Returns the number of items in the bitmap.
-
#clear ⇒ nil
(also: #reset)
Clears the bitmap, removing all items.
-
#contains(item) ⇒ Boolean
(also: #include?, #member?, #contains?)
Check the bitmap for the presence of an item.
-
#difference(other) ⇒ Roaring::Bitmap
(also: #-, #and_not)
A difference between the two bitmaps.
-
#difference_len(other) ⇒ Integer
(also: #and_not_len)
Computes the difference of the bitmap with another bitmap and returns the cardinality of the result.
-
#disjoint?(other) ⇒ Boolean
Checks if the bitmaps are disjoint.
- #each ⇒ Object
-
#empty? ⇒ Boolean
Checks if the bitmap is empty.
-
#eql?(other) ⇒ Boolean
(also: #==)
Checks if the bitmap is equal to another bitmap.
-
#full? ⇒ Boolean
Checks if the bitmap is full.
- #hash ⇒ Object
-
#insert(item) ⇒ Boolean
(also: #<<)
Inserts an item into the bitmap.
-
#insert_many(items) ⇒ Integer
Inserts multiple items into the bitmap.
-
#intersection(other) ⇒ Roaring::Bitmap
(also: #&, #and)
Intersects the bitmap with another bitmap.
-
#intersection_len(other) ⇒ Integer
(also: #and_len)
Computes the intersection of the bitmap with another bitmap and returns the cardinality of the result.
-
#max ⇒ Integer?
(also: #last)
Retrieves the maximum value in the bitmap.
-
#min ⇒ Integer?
(also: #first)
Retrieves the minimum value in the bitmap.
-
#nth(item) ⇒ Integer?
Retrieves the nth integer in the bitmap, or nil if the bitmap is empty or if n is out of bounds.
-
#rank(item) ⇒ Integer
Returns the number of integers that are <= value.
-
#remove(item) ⇒ Boolean
(also: #delete)
Removes an item from the bitmap.
-
#serialize ⇒ String
Serializes the bitmap into its binary representation.
-
#subset?(other) ⇒ Boolean
Checks if the bitmap is a subset of another bitmap.
-
#superset?(other) ⇒ Boolean
Checks if the bitmap is a superset of another bitmap.
-
#symmetric_difference(other) ⇒ Roaring::Bitmap
(also: #^, #xor)
A symmetric difference between the two bitmaps.
-
#symmetric_difference_len(other) ⇒ Integer
(also: #xor_len)
Computes the symmetric difference of the bitmap with another bitmap and returns the cardinality of the result.
-
#to_a ⇒ Array<Integer>
Returns an array of all the items in the bitmap.
-
#union(other) ⇒ Roaring::Bitmap
(also: #|, #or)
Union the bitmap with another bitmap.
-
#union_len(other) ⇒ Integer
(also: #or_len)
Computes the union of the bitmap with another bitmap and returns the cardinality of the result.
Class Method Details
._load(args) ⇒ Object
58 59 60 |
# File 'lib/roaring.rb', line 58 def self._load(args) deserialize(args) end |
.deserialize(rstr) ⇒ Roaring::Bitmap
Deserializes a bitmap from its binary representation.
711 712 713 714 715 716 |
# File 'ext/roaring/src/lib.rs', line 711
fn deserialize(rstr: RString) -> Result<Self, Error> {
let buf = unsafe { rstr.as_slice() };
let d = RoaringBitmap::deserialize_from(&mut &buf[..]).unwrap();
Ok(Self(RefCell::new(Wrapper { _data: d })))
}
}
|
.from_a(array) ⇒ Roaring::Bitmap
Initializes a new bitmap from an array of integers.
71 72 73 74 75 76 |
# File 'ext/roaring/src/lib.rs', line 71
fn from_array(array: RArray) -> Self {
let values = array.to_vec::<u32>().unwrap();
Self(RefCell::new(Wrapper {
_data: RoaringBitmap::from_iter(values),
}))
}
|
.full ⇒ Roaring::Bitmap
Initializes a new bitmap with all bits set to 1.
53 54 55 56 57 |
# File 'ext/roaring/src/lib.rs', line 53
fn new_full() -> Self {
Self(RefCell::new(Wrapper {
_data: RoaringBitmap::full(),
}))
}
|
.new ⇒ Roaring::Bitmap
Initializes a new empty bitmap.
37 38 39 40 41 |
# File 'ext/roaring/src/lib.rs', line 37
fn new() -> Self {
Self(RefCell::new(Wrapper {
_data: RoaringBitmap::new(),
}))
}
|
Instance Method Details
#_dump(_level) ⇒ Object
62 63 64 |
# File 'lib/roaring.rb', line 62 def _dump(_level) serialize end |
#byte_size ⇒ Integer
Returns the size of the bitmap in bytes.
655 656 657 |
# File 'ext/roaring/src/lib.rs', line 655
fn byte_size(&self) -> Result<usize, Error> {
Ok(self.0.borrow()._data.serialized_size())
}
|
#cardinality ⇒ Integer Also known as: size, count, length
Returns the number of items in the bitmap.
210 211 212 |
# File 'ext/roaring/src/lib.rs', line 210
fn len(&self) -> Result<u64, Error> {
Ok(self.0.borrow()._data.len())
}
|
#clear ⇒ nil Also known as: reset
Clears the bitmap, removing all items.
194 195 196 197 |
# File 'ext/roaring/src/lib.rs', line 194
fn clear(&self) -> Result<(), Error> {
self.0.borrow_mut()._data.clear();
Ok(())
}
|
#contains(item) ⇒ Boolean Also known as: include?, member?, contains?
Check the bitmap for the presence of an item.
162 163 164 |
# File 'ext/roaring/src/lib.rs', line 162
fn contains(&self, item: u32) -> Result<bool, Error> {
Ok(self.0.borrow()._data.contains(item))
}
|
#difference(other) ⇒ Roaring::Bitmap Also known as: -, and_not
A difference between the two bitmaps. Bitwise AND NOT.
498 499 500 501 502 503 504 |
# File 'ext/roaring/src/lib.rs', line 498
fn difference(&self, other: &Self) -> Result<Self, Error> {
let lhs = &self.0.borrow()._data;
let rhs = &other.0.borrow()._data;
let d = lhs.sub(rhs);
Ok(Self(RefCell::new(Wrapper { _data: d })))
}
|
#difference_len(other) ⇒ Integer Also known as: and_not_len
Computes the difference of the bitmap with another bitmap and returns the cardinality of the result. Useful for when you want to know the length of the result but not create a new bitmap.
522 523 524 525 526 527 528 |
# File 'ext/roaring/src/lib.rs', line 522
fn difference_len(&self, other: &Self) -> Result<u64, Error> {
Ok(self
.0
.borrow()
._data
.difference_len(&other.0.borrow()._data))
}
|
#disjoint?(other) ⇒ Boolean
Checks if the bitmaps are disjoint.
331 332 333 |
# File 'ext/roaring/src/lib.rs', line 331
fn is_disjoint(&self, other: &Self) -> Result<bool, Error> {
Ok(self.0.borrow()._data.is_disjoint(&other.0.borrow()._data))
}
|
#each {|Integer| ... } ⇒ Roaring::Bitmap #each ⇒ Enumerator
622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 |
# File 'ext/roaring/src/lib.rs', line 622
fn each(rb_self: Obj<Self>) -> Result<Value, Error> {
if block_given() {
let self_struct = rb_self.get();
let data = &self_struct.0.borrow()._data;
let block = block_proc().unwrap();
for i in data.iter() {
let rparams = RArray::with_capacity(1);
rparams.push(i).unwrap();
match block.call::<RArray, Option<Value>>(rparams) {
Ok(_) => {}
Err(e) => {
return Err(e);
}
}
}
Ok(*rb_self)
} else {
Ok(*rb_self.enumeratorize("each", ()))
}
}
|
#empty? ⇒ Boolean
Checks if the bitmap is empty.
229 230 231 |
# File 'ext/roaring/src/lib.rs', line 229
fn is_empty(&self) -> Result<bool, Error> {
Ok(self.0.borrow()._data.is_empty())
}
|
#eql?(other) ⇒ Boolean Also known as: ==
Checks if the bitmap is equal to another bitmap.
674 675 676 |
# File 'ext/roaring/src/lib.rs', line 674
fn eql(&self, other: &Self) -> Result<bool, Error> {
Ok(self.0.borrow()._data == other.0.borrow()._data)
}
|
#full? ⇒ Boolean
Checks if the bitmap is full.
248 249 250 |
# File 'ext/roaring/src/lib.rs', line 248
fn is_full(&self) -> Result<bool, Error> {
Ok(self.0.borrow()._data.is_full())
}
|
#hash ⇒ Object
54 55 56 |
# File 'lib/roaring.rb', line 54 def hash to_a.hash end |
#insert(item) ⇒ Boolean Also known as: <<
Inserts an item into the bitmap.
95 96 97 |
# File 'ext/roaring/src/lib.rs', line 95
fn insert(&self, item: u32) -> Result<bool, Error> {
Ok(self.0.borrow_mut()._data.insert(item))
}
|
#insert_many(items) ⇒ Integer
Inserts multiple items into the bitmap.
112 113 114 115 116 117 118 119 120 121 122 |
# File 'ext/roaring/src/lib.rs', line 112
fn insert_many(&self, items: RArray) -> Result<u32, Error> {
let values = items.to_vec::<u32>()?;
let mut inserted = 0;
for value in values {
if self.0.borrow_mut()._data.insert(value) {
inserted += 1;
}
}
Ok(inserted)
}
|
#intersection(other) ⇒ Roaring::Bitmap Also known as: &, and
Intersects the bitmap with another bitmap. Bitwise AND.
449 450 451 452 453 454 455 |
# File 'ext/roaring/src/lib.rs', line 449
fn intersection(&self, other: &Self) -> Result<Self, Error> {
let lhs = &self.0.borrow()._data;
let rhs = &other.0.borrow()._data;
let d = lhs.bitand(rhs);
Ok(Self(RefCell::new(Wrapper { _data: d })))
}
|
#intersection_len(other) ⇒ Integer Also known as: and_len
Computes the intersection of the bitmap with another bitmap and returns the cardinality of the result. Useful for when you want to know the length of the result but not create a new bitmap.
473 474 475 476 477 478 479 |
# File 'ext/roaring/src/lib.rs', line 473
fn intersection_len(&self, other: &Self) -> Result<u64, Error> {
Ok(self
.0
.borrow()
._data
.intersection_len(&other.0.borrow()._data))
}
|
#max ⇒ Integer? Also known as: last
Retrieves the maximum value in the bitmap.
267 268 269 |
# File 'ext/roaring/src/lib.rs', line 267
fn max(&self) -> Result<Option<u32>, Error> {
Ok(self.0.borrow()._data.max())
}
|
#min ⇒ Integer? Also known as: first
Retrieves the minimum value in the bitmap.
286 287 288 |
# File 'ext/roaring/src/lib.rs', line 286
fn min(&self) -> Result<Option<u32>, Error> {
Ok(self.0.borrow()._data.min())
}
|
#nth(item) ⇒ Integer?
Retrieves the nth integer in the bitmap, or nil if the bitmap is empty or if n is out of bounds.
305 306 307 |
# File 'ext/roaring/src/lib.rs', line 305
fn select(&self, item: u32) -> Result<Option<u32>, Error> {
Ok(self.0.borrow()._data.select(item))
}
|
#rank(item) ⇒ Integer
Returns the number of integers that are <= value. rank(u32::MAX) == len(). This is also known as the rank or rank-select idiom.
591 592 593 |
# File 'ext/roaring/src/lib.rs', line 591
fn rank(&self, item: u32) -> Result<u64, Error> {
Ok(self.0.borrow()._data.rank(item))
}
|
#remove(item) ⇒ Boolean Also known as: delete
Removes an item from the bitmap.
141 142 143 |
# File 'ext/roaring/src/lib.rs', line 141
fn remove(&self, item: u32) -> Result<bool, Error> {
Ok(self.0.borrow_mut()._data.remove(item))
}
|
#serialize ⇒ String
Serializes the bitmap into its binary representation.
689 690 691 692 693 |
# File 'ext/roaring/src/lib.rs', line 689
fn serialize(&self) -> Result<RString, Error> {
let mut buf = vec![];
self.0.borrow()._data.serialize_into(&mut buf).unwrap();
Ok(RString::from_slice(&buf))
}
|
#subset?(other) ⇒ Boolean
Checks if the bitmap is a subset of another bitmap.
357 358 359 |
# File 'ext/roaring/src/lib.rs', line 357
fn is_subset(&self, other: &Self) -> Result<bool, Error> {
Ok(self.0.borrow()._data.is_subset(&other.0.borrow()._data))
}
|
#superset?(other) ⇒ Boolean
Checks if the bitmap is a superset of another bitmap.
383 384 385 |
# File 'ext/roaring/src/lib.rs', line 383
fn is_superset(&self, other: &Self) -> Result<bool, Error> {
Ok(self.0.borrow()._data.is_superset(&other.0.borrow()._data))
}
|
#symmetric_difference(other) ⇒ Roaring::Bitmap Also known as: ^, xor
A symmetric difference between the two bitmaps. This is equivalent to the union of the two bitmaps minus the intersection. Bitwise XOR.
547 548 549 550 551 552 |
# File 'ext/roaring/src/lib.rs', line 547
fn symmetric_difference(&self, other: &Self) -> Result<Self, Error> {
let lhs = &self.0.borrow()._data;
let rhs = &other.0.borrow()._data;
let d = lhs.bitxor(rhs);
Ok(Self(RefCell::new(Wrapper { _data: d })))
}
|
#symmetric_difference_len(other) ⇒ Integer Also known as: xor_len
Computes the symmetric difference of the bitmap with another bitmap and returns the cardinality of the result. Useful for when you want to know the length of the result but not create a new bitmap.
570 571 572 573 574 575 576 |
# File 'ext/roaring/src/lib.rs', line 570
fn symmetric_difference_len(&self, other: &Self) -> Result<u64, Error> {
Ok(self
.0
.borrow()
._data
.symmetric_difference_len(&other.0.borrow()._data))
}
|
#to_a ⇒ Array<Integer>
Returns an array of all the items in the bitmap.
177 178 179 |
# File 'ext/roaring/src/lib.rs', line 177
fn to_vec(&self) -> Result<Vec<u32>, Error> {
Ok(self.0.borrow()._data.iter().collect())
}
|
#union(other) ⇒ Roaring::Bitmap Also known as: |, or
Union the bitmap with another bitmap. Bitwise OR.
404 405 406 407 408 409 410 |
# File 'ext/roaring/src/lib.rs', line 404
fn union(&self, other: &Self) -> Result<Self, Error> {
let lhs = &self.0.borrow()._data;
let rhs = &other.0.borrow()._data;
let d = lhs.bitor(rhs);
Ok(Self(RefCell::new(Wrapper { _data: d })))
}
|
#union_len(other) ⇒ Integer Also known as: or_len
Computes the union of the bitmap with another bitmap and returns the cardinality of the result. Useful for when you want to know the length of the result but not create a new bitmap.
428 429 430 |
# File 'ext/roaring/src/lib.rs', line 428
fn union_len(&self, other: &Self) -> Result<u64, Error> {
Ok(self.0.borrow()._data.union_len(&other.0.borrow()._data))
}
|