Class: Roaring::Bitmap32

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

Returns:



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`.

Returns:

  • (Boolean)

    ‘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`.

Returns:

  • (Boolean)

    ‘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.

Returns:

  • (Integer)

    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`.

Returns:

  • (Boolean)

    ‘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`.

Returns:

  • (Integer, nil)

    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: <<

Parameters:

  • val (Integer)

    the value to add



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.

Returns:

  • (Boolean)

    ‘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`.

Returns:

  • (Bitmap32)

    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.

Returns:

  • (self)

    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`.

Returns:

  • (Bitmap32)

    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.

Returns:

  • (self)

    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);
}

#cardinalityInteger Also known as: size, length, count

Returns the number of elements in the bitmap.

Returns:

  • (Integer)

    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);
}

#clearObject

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

Returns:

  • (Boolean)

#eachself

Returns:

  • (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`.

Returns:

  • (Boolean)

    ‘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));
}

#hashObject Originally defined in module BitmapCommon

#include?(val) ⇒ Boolean Also known as: ===

Returns ‘true` if the bitmap is contains `val`, otherwise `false`.

Returns:

  • (Boolean)

    ‘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

#inspectString Originally defined in module BitmapCommon

Returns a programmer-readable representation of the bitmap.

Examples:

Small bitmap

Roaring::Bitmap32[1,2,3].inspect #=> "#<Roaring::Bitmap32 {1, 2, 3}>"

Large bitmap

Roaring::Bitmap32[1..1000].inspect #=> "#<Roaring::Bitmap32 (1000 values)>"

Returns:

  • (String)

    a programmer-readable representation of the bitmap

#intersect?(other) ⇒ Boolean

Returns ‘true` if `self` intersects `other`, otherwise `false`.

Returns:

  • (Boolean)

    ‘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);
}

#maxInteger? Also known as: last

Returns The largest integer in the bitmap, or ‘nil` if it is empty.

Returns:

  • (Integer, nil)

    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);
    }
}

#minInteger? Also known as: first

Returns The smallest integer in the bitmap, or ‘nil` if it is empty.

Returns:

  • (Integer, nil)

    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`.

Returns:

  • (Bitmap32)

    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.

Returns:

  • (self)

    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.

Returns:

  • (Boolean)

    ‘true` if `self` is a strict subset of `other`, otherwise `false`

#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.

Returns:

  • (self, nil)

    ‘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_optimizeBoolean

Returns whether the result has at least one run container.

Returns:

  • (Boolean)

    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));
}

#serializestring

Returns:

  • (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;
}

#statisticsHash

Returns:

  • (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.

Returns:

  • (Boolean)

    ‘true` if `self` is a strict subset of `other`, otherwise `false`

#to_setObject 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.

Returns:

  • (Bitmap32)

    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.

Returns:

  • (self)

    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);
}