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) ⇒ Object



235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'ext/roaring/bitmap32.c', line 235

static VALUE rb_roaring32_deserialize(VALUE self, VALUE str)
{
    StringValue(str);

    roaring_bitmap_t *bitmap = roaring_bitmap_portable_deserialize_safe(RSTRING_PTR(str), RSTRING_LEN(str));
    RB_GC_GUARD(str);

    if (!bitmap) {
        rb_raise(rb_eArgError, "invalid Roaring::Bitmap32 serialization");
    }

    return TypedData_Wrap_Struct(cRoaringBitmap32, &roaring_type, bitmap);
}

Instance Method Details

#<(other) ⇒ Object Also known as: proper_subset?



377
378
379
380
# File 'ext/roaring/bitmap32.c', line 377

static VALUE rb_roaring32_lt(VALUE self, VALUE other)
{
    return rb_roaring32_binary_op_bool(self, other, roaring_bitmap_is_strict_subset);
}

#<=(other) ⇒ Object Also known as: subset?



384
385
386
387
# File 'ext/roaring/bitmap32.c', line 384

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) ⇒ Object Also known as: eql?



370
371
372
373
# File 'ext/roaring/bitmap32.c', line 370

static VALUE rb_roaring32_eq(VALUE self, VALUE other)
{
    return rb_roaring32_binary_op_bool(self, other, roaring_bitmap_equals);
}

#[](rankv) ⇒ Object



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) ⇒ Object



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) ⇒ Object Also known as: &, intersection



342
343
344
345
# File 'ext/roaring/bitmap32.c', line 342

static VALUE rb_roaring32_and(VALUE self, VALUE other)
{
    return rb_roaring32_binary_op(self, other, roaring_bitmap_and);
}

#and!(other) ⇒ Object



314
315
316
317
# File 'ext/roaring/bitmap32.c', line 314

static VALUE rb_roaring32_and_inplace(VALUE self, VALUE other)
{
    return rb_roaring32_binary_op_inplace(self, other, roaring_bitmap_and_inplace);
}

#andnot(other) ⇒ Object Also known as: -, difference



363
364
365
366
# File 'ext/roaring/bitmap32.c', line 363

static VALUE rb_roaring32_andnot(VALUE self, VALUE other)
{
    return rb_roaring32_binary_op(self, other, roaring_bitmap_andnot);
}

#andnot!(other) ⇒ Object



335
336
337
338
# File 'ext/roaring/bitmap32.c', line 335

static VALUE rb_roaring32_andnot_inplace(VALUE self, VALUE other)
{
    return rb_roaring32_binary_op_inplace(self, other, roaring_bitmap_andnot_inplace);
}

#cardinalityObject Also known as: size, length, count



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



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)

#eachObject



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?Object



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) ⇒ Object Also known as: ===



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) ⇒ Object



391
392
393
394
# File 'ext/roaring/bitmap32.c', line 391

static VALUE rb_roaring32_intersect_p(VALUE self, VALUE other)
{
    return rb_roaring32_binary_op_bool(self, other, roaring_bitmap_intersect);
}

#maxObject Also known as: last



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

#minObject Also known as: first



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) ⇒ Object Also known as: |, +, union



349
350
351
352
# File 'ext/roaring/bitmap32.c', line 349

static VALUE rb_roaring32_or(VALUE self, VALUE other)
{
    return rb_roaring32_binary_op(self, other, roaring_bitmap_or);
}

#or!(other) ⇒ Object



321
322
323
324
# File 'ext/roaring/bitmap32.c', line 321

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



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) ⇒ Object Also known as: delete?



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



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_optimizeObject



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

#serializeObject



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

#statisticsObject



251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# File 'ext/roaring/bitmap32.c', line 251

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) ⇒ Object Also known as: ^



356
357
358
359
# File 'ext/roaring/bitmap32.c', line 356

static VALUE rb_roaring32_xor(VALUE self, VALUE other)
{
    return rb_roaring32_binary_op(self, other, roaring_bitmap_xor);
}

#xor!(other) ⇒ Object



328
329
330
331
# File 'ext/roaring/bitmap32.c', line 328

static VALUE rb_roaring32_xor_inplace(VALUE self, VALUE other)
{
    return rb_roaring32_binary_op_inplace(self, other, roaring_bitmap_xor_inplace);
}