Class: Roaring::Bitmap32
- Inherits:
-
Object
- Object
- Roaring::Bitmap32
- Extended by:
- Roaring::BitmapCommon::ClassMethods
- Includes:
- BitmapCommon
- Defined in:
- lib/roaring.rb,
ext/roaring/bitmap32.c
Constant Summary collapse
- MIN =
0
- MAX =
(2**32) - 1
- RANGE =
MIN..MAX
Class Method Summary collapse
-
.[](*args) ⇒ Object
extended
from Roaring::BitmapCommon::ClassMethods
Convenience method for building a bitmap.
- ._load(args) ⇒ Object extended from Roaring::BitmapCommon::ClassMethods
- .deserialize(str) ⇒ Bitmap32
Instance Method Summary collapse
-
#<(other) ⇒ Boolean
(also: #proper_subset?)
‘true` if `self` is a strict subset of `other`, otherwise `false`.
-
#<=(other) ⇒ Boolean
(also: #subset?)
‘true` if `self` is a subset of `other`, otherwise `false`.
-
#<=>(other) ⇒ Integer
included
from BitmapCommon
Returns 0 if the bitmaps are equal, -1 / +1 if the set is a subset / superset of the given set, or nil if they both have unique elements.
-
#==(other) ⇒ Boolean
(also: #eql?)
‘true` if both bitmaps contain all the same elements, otherwise `false`.
-
#[](rankv) ⇒ Integer?
The nth integer in the bitmap, or ‘nil` if `rankv` is `>= cardinality`.
- #_dump(level) ⇒ Object included from BitmapCommon
- #add(val) ⇒ Object (also: #<<)
-
#add?(val) ⇒ Boolean
‘self` if value was add, `nil` if value was already in the bitmap.
- #add_range(min, max) ⇒ Object included from BitmapCommon
- #add_range_closed(minv, maxv) ⇒ Object
-
#and(other) ⇒ Bitmap32
(also: #&, #intersection)
A new bitmap containing all elements in both ‘self` and `other`.
-
#and!(other) ⇒ self
The modified Bitmap.
-
#andnot(other) ⇒ Bitmap32
(also: #-, #difference)
A new bitmap containing all elements in ‘self`, but not in `other`.
-
#andnot!(other) ⇒ self
The modified Bitmap.
-
#cardinality ⇒ Integer
(also: #size, #length, #count)
The number of elements in the bitmap.
-
#clear ⇒ Object
Removes all elements from the bitmap.
- #disjoint?(other) ⇒ Boolean included from BitmapCommon
- #each ⇒ self
-
#empty? ⇒ Boolean
‘true` if the bitmap is empty, otherwise `false`.
- #hash ⇒ Object included from BitmapCommon
-
#include?(val) ⇒ Boolean
(also: #===)
‘true` if the bitmap is contains `val`, otherwise `false`.
- #initialize(enum = nil) ⇒ Object included from BitmapCommon
- #initialize_copy(other) ⇒ Object included from BitmapCommon
-
#inspect ⇒ String
included
from BitmapCommon
A programmer-readable representation of the bitmap.
-
#intersect?(other) ⇒ Boolean
‘true` if `self` intersects `other`, otherwise `false`.
-
#max ⇒ Integer?
(also: #last)
The largest integer in the bitmap, or ‘nil` if it is empty.
-
#min ⇒ Integer?
(also: #first)
The smallest integer in the bitmap, or ‘nil` if it is empty.
-
#or(other) ⇒ Bitmap32
(also: #|, #+, #union)
A new bitmap containing all elements in either ‘self` or `other`.
-
#or!(other) ⇒ self
The modified Bitmap.
-
#proper_superset?(other) ⇒ Boolean
(also: #>)
included
from BitmapCommon
Check if ‘self` is a strict superset of `other`.
-
#remove(val) ⇒ Object
(also: #delete)
Removes an element from the bitmap.
-
#remove?(val) ⇒ self?
(also: #delete?)
‘self` if value was removed, `nil` if the value wasn’t in the bitmap.
-
#replace(other) ⇒ Object
Replaces the contents of ‘self` with another bitmap.
-
#run_optimize ⇒ Boolean
Whether the result has at least one run container.
- #serialize ⇒ string
- #statistics ⇒ Hash
-
#superset?(other) ⇒ Boolean
(also: #>=)
included
from BitmapCommon
Check if ‘self` is a superset of `other`.
- #to_set ⇒ Object included from BitmapCommon
-
#xor(other) ⇒ Bitmap32
(also: #^)
A new bitmap containing all elements in one of ‘self` or `other`, but not both.
-
#xor!(other) ⇒ self
The modified Bitmap.
Class Method Details
.[](*args) ⇒ Object Originally defined in module Roaring::BitmapCommon::ClassMethods
Convenience method for building a bitmap
._load(args) ⇒ Object Originally defined in module Roaring::BitmapCommon::ClassMethods
.deserialize(str) ⇒ Bitmap32
233 234 235 236 237 238 |
# File 'ext/roaring/bitmap32.c', line 233
static VALUE rb_roaring32_deserialize(VALUE self, VALUE str)
{
roaring_bitmap_t *bitmap = roaring_bitmap_portable_deserialize_safe(RSTRING_PTR(str), RSTRING_LEN(str));
return TypedData_Wrap_Struct(cRoaringBitmap32, &roaring_type, bitmap);
}
|
Instance Method Details
#<(other) ⇒ Boolean Also known as: proper_subset?
Returns ‘true` if `self` is a strict subset of `other`, otherwise `false`.
368 369 370 371 |
# File 'ext/roaring/bitmap32.c', line 368
static VALUE rb_roaring32_lt(VALUE self, VALUE other)
{
return rb_roaring32_binary_op_bool(self, other, roaring_bitmap_is_strict_subset);
}
|
#<=(other) ⇒ Boolean Also known as: subset?
Returns ‘true` if `self` is a subset of `other`, otherwise `false`.
375 376 377 378 |
# File 'ext/roaring/bitmap32.c', line 375
static VALUE rb_roaring32_lte(VALUE self, VALUE other)
{
return rb_roaring32_binary_op_bool(self, other, roaring_bitmap_is_subset);
}
|
#<=>(other) ⇒ Integer Originally defined in module BitmapCommon
Returns 0 if the bitmaps are equal, -1 / +1 if the set is a subset / superset of the given set, or nil if they both have unique elements.
#==(other) ⇒ Boolean Also known as: eql?
Returns ‘true` if both bitmaps contain all the same elements, otherwise `false`.
361 362 363 364 |
# File 'ext/roaring/bitmap32.c', line 361
static VALUE rb_roaring32_eq(VALUE self, VALUE other)
{
return rb_roaring32_binary_op_bool(self, other, roaring_bitmap_equals);
}
|
#[](rankv) ⇒ Integer?
Returns The nth integer in the bitmap, or ‘nil` if `rankv` is `>= cardinality`.
165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'ext/roaring/bitmap32.c', line 165
static VALUE rb_roaring32_aref(VALUE self, VALUE rankv)
{
roaring_bitmap_t *data = get_bitmap(self);
uint32_t rank = NUM2UINT32(rankv);
uint32_t val;
if (roaring_bitmap_select(data, rank, &val)) {
return UINT2NUM(val);
} else {
return Qnil;
}
return self;
}
|
#_dump(level) ⇒ Object Originally defined in module BitmapCommon
#add(val) ⇒ Object Also known as: <<
71 72 73 74 75 76 77 78 |
# File 'ext/roaring/bitmap32.c', line 71
static VALUE rb_roaring32_add(VALUE self, VALUE val)
{
roaring_bitmap_t *data = get_bitmap(self);
uint32_t num = NUM2UINT32(val);
roaring_bitmap_add(data, num);
return self;
}
|
#add?(val) ⇒ Boolean
Returns ‘self` if value was add, `nil` if value was already in the bitmap.
83 84 85 86 87 88 89 |
# File 'ext/roaring/bitmap32.c', line 83
static VALUE rb_roaring32_add_p(VALUE self, VALUE val)
{
roaring_bitmap_t *data = get_bitmap(self);
uint32_t num = NUM2UINT32(val);
return roaring_bitmap_add_checked(data, num) ? self : Qnil;
}
|
#add_range(min, max) ⇒ Object Originally defined in module BitmapCommon
#add_range_closed(minv, maxv) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 |
# File 'ext/roaring/bitmap32.c', line 91
static VALUE rb_roaring32_add_range_closed(VALUE self, VALUE minv, VALUE maxv)
{
roaring_bitmap_t *data = get_bitmap(self);
uint32_t min = NUM2UINT32(minv);
uint32_t max = NUM2UINT32(maxv);
roaring_bitmap_add_range_closed(data, min, max);
return self;
}
|
#and(other) ⇒ Bitmap32 Also known as: &, intersection
Returns a new bitmap containing all elements in both ‘self` and `other`.
333 334 335 336 |
# File 'ext/roaring/bitmap32.c', line 333
static VALUE rb_roaring32_and(VALUE self, VALUE other)
{
return rb_roaring32_binary_op(self, other, roaring_bitmap_and);
}
|
#and!(other) ⇒ self
Returns the modified Bitmap.
305 306 307 308 |
# File 'ext/roaring/bitmap32.c', line 305
static VALUE rb_roaring32_and_inplace(VALUE self, VALUE other)
{
return rb_roaring32_binary_op_inplace(self, other, roaring_bitmap_and_inplace);
}
|
#andnot(other) ⇒ Bitmap32 Also known as: -, difference
Returns a new bitmap containing all elements in ‘self`, but not in `other`.
354 355 356 357 |
# File 'ext/roaring/bitmap32.c', line 354
static VALUE rb_roaring32_andnot(VALUE self, VALUE other)
{
return rb_roaring32_binary_op(self, other, roaring_bitmap_andnot);
}
|
#andnot!(other) ⇒ self
Returns the modified Bitmap.
326 327 328 329 |
# File 'ext/roaring/bitmap32.c', line 326
static VALUE rb_roaring32_andnot_inplace(VALUE self, VALUE other)
{
return rb_roaring32_binary_op_inplace(self, other, roaring_bitmap_andnot_inplace);
}
|
#cardinality ⇒ Integer Also known as: size, length, count
Returns the number of elements in the bitmap.
62 63 64 65 66 67 |
# File 'ext/roaring/bitmap32.c', line 62
static VALUE rb_roaring32_cardinality(VALUE self)
{
roaring_bitmap_t *data = get_bitmap(self);
uint64_t cardinality = roaring_bitmap_get_cardinality(data);
return ULONG2NUM(cardinality);
}
|
#clear ⇒ Object
Removes all elements from the bitmap
142 143 144 145 146 147 |
# File 'ext/roaring/bitmap32.c', line 142
static VALUE rb_roaring32_clear(VALUE self)
{
roaring_bitmap_t *data = get_bitmap(self);
roaring_bitmap_clear(data);
return self;
}
|
#disjoint?(other) ⇒ Boolean Originally defined in module BitmapCommon
#each ⇒ self
156 157 158 159 160 161 |
# File 'ext/roaring/bitmap32.c', line 156
static VALUE rb_roaring32_each(VALUE self)
{
roaring_bitmap_t *data = get_bitmap(self);
roaring_iterate(data, rb_roaring32_each_i, NULL);
return self;
}
|
#empty? ⇒ Boolean
Returns ‘true` if the bitmap is empty, otherwise `false`.
135 136 137 138 139 |
# File 'ext/roaring/bitmap32.c', line 135
static VALUE rb_roaring32_empty_p(VALUE self)
{
roaring_bitmap_t *data = get_bitmap(self);
return RBOOL(roaring_bitmap_is_empty(data));
}
|
#hash ⇒ Object Originally defined in module BitmapCommon
#include?(val) ⇒ Boolean Also known as: ===
Returns ‘true` if the bitmap is contains `val`, otherwise `false`.
126 127 128 129 130 131 132 |
# File 'ext/roaring/bitmap32.c', line 126
static VALUE rb_roaring32_include_p(VALUE self, VALUE val)
{
roaring_bitmap_t *data = get_bitmap(self);
uint32_t num = NUM2UINT32(val);
return RBOOL(roaring_bitmap_contains(data, num));
}
|
#initialize(enum = nil) ⇒ Object Originally defined in module BitmapCommon
#initialize_copy(other) ⇒ Object Originally defined in module BitmapCommon
#inspect ⇒ String Originally defined in module BitmapCommon
Returns a programmer-readable representation of the bitmap.
#intersect?(other) ⇒ Boolean
Returns ‘true` if `self` intersects `other`, otherwise `false`.
382 383 384 385 |
# File 'ext/roaring/bitmap32.c', line 382
static VALUE rb_roaring32_intersect_p(VALUE self, VALUE other)
{
return rb_roaring32_binary_op_bool(self, other, roaring_bitmap_intersect);
}
|
#max ⇒ Integer? Also known as: last
Returns The largest integer in the bitmap, or ‘nil` if it is empty.
196 197 198 199 200 201 202 203 204 205 206 |
# File 'ext/roaring/bitmap32.c', line 196
static VALUE rb_roaring32_max(VALUE self)
{
roaring_bitmap_t *data = get_bitmap(self);
if (roaring_bitmap_is_empty(data)) {
return Qnil;
} else {
uint32_t val = roaring_bitmap_maximum(data);
return UINT2NUM(val);
}
}
|
#min ⇒ Integer? Also known as: first
Returns The smallest integer in the bitmap, or ‘nil` if it is empty.
182 183 184 185 186 187 188 189 190 191 192 |
# File 'ext/roaring/bitmap32.c', line 182
static VALUE rb_roaring32_min(VALUE self)
{
roaring_bitmap_t *data = get_bitmap(self);
if (roaring_bitmap_is_empty(data)) {
return Qnil;
} else {
uint32_t val = roaring_bitmap_minimum(data);
return UINT2NUM(val);
}
}
|
#or(other) ⇒ Bitmap32 Also known as: |, +, union
Returns a new bitmap containing all elements in either ‘self` or `other`.
340 341 342 343 |
# File 'ext/roaring/bitmap32.c', line 340
static VALUE rb_roaring32_or(VALUE self, VALUE other)
{
return rb_roaring32_binary_op(self, other, roaring_bitmap_or);
}
|
#or!(other) ⇒ self
Returns the modified Bitmap.
312 313 314 315 |
# File 'ext/roaring/bitmap32.c', line 312
static VALUE rb_roaring32_or_inplace(VALUE self, VALUE other)
{
return rb_roaring32_binary_op_inplace(self, other, roaring_bitmap_or_inplace);
}
|
#proper_superset?(other) ⇒ Boolean Also known as: > Originally defined in module BitmapCommon
Check if ‘self` is a strict superset of `other`. A strict superset requires that `self` contain all of `other`’s elemtents, but that they aren’t exactly equal.
#remove(val) ⇒ Object Also known as: delete
Removes an element from the bitmap
104 105 106 107 108 109 110 111 |
# File 'ext/roaring/bitmap32.c', line 104
static VALUE rb_roaring32_remove(VALUE self, VALUE val)
{
roaring_bitmap_t *data = get_bitmap(self);
uint32_t num = NUM2UINT32(val);
roaring_bitmap_remove(data, num);
return self;
}
|
#remove?(val) ⇒ self? Also known as: delete?
Returns ‘self` if value was removed, `nil` if the value wasn’t in the bitmap.
117 118 119 120 121 122 123 |
# File 'ext/roaring/bitmap32.c', line 117
static VALUE rb_roaring32_remove_p(VALUE self, VALUE val)
{
roaring_bitmap_t *data = get_bitmap(self);
uint32_t num = NUM2UINT32(val);
return roaring_bitmap_remove_checked(data, num) ? self : Qnil;
}
|
#replace(other) ⇒ Object
Replaces the contents of ‘self` with another bitmap
52 53 54 55 56 57 58 59 |
# File 'ext/roaring/bitmap32.c', line 52
static VALUE rb_roaring32_replace(VALUE self, VALUE other) {
roaring_bitmap_t *self_data = get_bitmap(self);
roaring_bitmap_t *other_data = get_bitmap(other);
roaring_bitmap_overwrite(self_data, other_data);
return self;
}
|
#run_optimize ⇒ Boolean
Returns whether the result has at least one run container.
210 211 212 213 214 |
# File 'ext/roaring/bitmap32.c', line 210
static VALUE rb_roaring32_run_optimize(VALUE self)
{
roaring_bitmap_t *data = get_bitmap(self);
return RBOOL(roaring_bitmap_run_optimize(data));
}
|
#serialize ⇒ string
218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'ext/roaring/bitmap32.c', line 218
static VALUE rb_roaring32_serialize(VALUE self)
{
roaring_bitmap_t *data = get_bitmap(self);
size_t size = roaring_bitmap_portable_size_in_bytes(data);
VALUE str = rb_str_buf_new(size);
size_t written = roaring_bitmap_portable_serialize(data, RSTRING_PTR(str));
rb_str_set_len(str, written);
return str;
}
|
#statistics ⇒ Hash
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
# File 'ext/roaring/bitmap32.c', line 242
static VALUE rb_roaring32_statistics(VALUE self)
{
roaring_bitmap_t *data = get_bitmap(self);
roaring_statistics_t stat;
roaring_bitmap_statistics(data, &stat);
VALUE ret = rb_hash_new();
#define ADD_STAT(name) \
rb_hash_aset(ret, rb_id2sym(rb_intern(#name)), ULL2NUM(stat.name))
ADD_STAT(n_containers);
ADD_STAT(n_array_containers);
ADD_STAT(n_run_containers);
ADD_STAT(n_bitset_containers);
ADD_STAT(n_values_array_containers);
ADD_STAT(n_values_run_containers);
ADD_STAT(n_values_bitset_containers);
ADD_STAT(n_bytes_array_containers);
ADD_STAT(n_bytes_run_containers);
ADD_STAT(n_bytes_bitset_containers);
ADD_STAT(max_value);
ADD_STAT(min_value);
// ADD_STAT(sum_value); // deprecated, skipped
ADD_STAT(cardinality);
#undef ADD_STAT
return ret;
}
|
#superset?(other) ⇒ Boolean Also known as: >= Originally defined in module BitmapCommon
Check if ‘self` is a superset of `other`. A superset requires that `self` contain all of `other`’s elemtents. They may be equal.
#to_set ⇒ Object Originally defined in module BitmapCommon
#xor(other) ⇒ Bitmap32 Also known as: ^
Returns a new bitmap containing all elements in one of ‘self` or `other`, but not both.
347 348 349 350 |
# File 'ext/roaring/bitmap32.c', line 347
static VALUE rb_roaring32_xor(VALUE self, VALUE other)
{
return rb_roaring32_binary_op(self, other, roaring_bitmap_xor);
}
|
#xor!(other) ⇒ self
Returns the modified Bitmap.
319 320 321 322 |
# File 'ext/roaring/bitmap32.c', line 319
static VALUE rb_roaring32_xor_inplace(VALUE self, VALUE other)
{
return rb_roaring32_binary_op_inplace(self, other, roaring_bitmap_xor_inplace);
}
|