Class: Roaring::Bitmap64

Inherits:
Object
  • Object
show all
Extended by:
Roaring::BitmapCommon::ClassMethods
Includes:
BitmapCommon
Defined in:
lib/roaring.rb,
ext/roaring/bitmap64.c

Constant Summary collapse

MIN =
0
MAX =
(2**64) - 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



209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'ext/roaring/bitmap64.c', line 209

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

    roaring64_bitmap_t *bitmap = roaring64_bitmap_portable_deserialize_safe(RSTRING_PTR(str), RSTRING_LEN(str));
    RB_GC_GUARD(str);

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

    return TypedData_Wrap_Struct(cRoaringBitmap64, &roaring64_type, bitmap);
}

Instance Method Details

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



353
354
355
356
# File 'ext/roaring/bitmap64.c', line 353

static VALUE rb_roaring64_lt(VALUE self, VALUE other)
{
    return rb_roaring64_binary_op_bool(self, other, roaring64_bitmap_is_strict_subset);
}

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



358
359
360
361
# File 'ext/roaring/bitmap64.c', line 358

static VALUE rb_roaring64_lte(VALUE self, VALUE other)
{
    return rb_roaring64_binary_op_bool(self, other, roaring64_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?



348
349
350
351
# File 'ext/roaring/bitmap64.c', line 348

static VALUE rb_roaring64_eq(VALUE self, VALUE other)
{
    return rb_roaring64_binary_op_bool(self, other, roaring64_bitmap_equals);
}

#[](rankv) ⇒ Object



151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'ext/roaring/bitmap64.c', line 151

static VALUE rb_roaring64_aref(VALUE self, VALUE rankv)
{
    roaring64_bitmap_t *data = get_bitmap(self);

    uint64_t rank = NUM2UINT64(rankv);
    uint64_t val;

    if (roaring64_bitmap_select(data, rank, &val)) {
        return ULL2NUM(val);
    } else {
        return Qnil;
    }
    return self;
}

#_dump(level) ⇒ Object Originally defined in module BitmapCommon

#add(val) ⇒ Object Also known as: <<



72
73
74
75
76
77
78
79
# File 'ext/roaring/bitmap64.c', line 72

static VALUE rb_roaring64_add(VALUE self, VALUE val)
{
    roaring64_bitmap_t *data = get_bitmap(self);

    uint64_t num = NUM2UINT64(val);
    roaring64_bitmap_add(data, num);
    return self;
}

#add?(val) ⇒ Boolean

Returns:

  • (Boolean)


81
82
83
84
85
86
87
# File 'ext/roaring/bitmap64.c', line 81

static VALUE rb_roaring64_add_p(VALUE self, VALUE val)
{
    roaring64_bitmap_t *data = get_bitmap(self);

    uint64_t num = NUM2UINT64(val);
    return roaring64_bitmap_add_checked(data, num) ? self : Qnil;
}

#add_range(min, max) ⇒ Object Originally defined in module BitmapCommon

#add_range_closed(minv, maxv) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
# File 'ext/roaring/bitmap64.c', line 89

static VALUE rb_roaring64_add_range_closed(VALUE self, VALUE minv, VALUE maxv)
{
    roaring64_bitmap_t *data = get_bitmap(self);

    uint64_t min = NUM2UINT64(minv);
    uint64_t max = NUM2UINT64(maxv);

    roaring64_bitmap_add_range_closed(data, min, max);

    return self;
}

#and(other) ⇒ Object Also known as: &, intersection



313
314
315
316
# File 'ext/roaring/bitmap64.c', line 313

static VALUE rb_roaring64_and(VALUE self, VALUE other)
{
    return rb_roaring64_binary_op(self, other, roaring64_bitmap_and);
}

#and!(other) ⇒ Object



293
294
295
296
# File 'ext/roaring/bitmap64.c', line 293

static VALUE rb_roaring64_and_inplace(VALUE self, VALUE other)
{
    return rb_roaring64_binary_op_inplace(self, other, roaring64_bitmap_and_inplace);
}

#and_cardinality(other) ⇒ Object



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

static VALUE rb_roaring64_and_cardinality(VALUE self, VALUE other)
{
    return rb_roaring64_binary_op_cardinality(self, other, roaring64_bitmap_and_cardinality);
}

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



343
344
345
346
# File 'ext/roaring/bitmap64.c', line 343

static VALUE rb_roaring64_andnot(VALUE self, VALUE other)
{
    return rb_roaring64_binary_op(self, other, roaring64_bitmap_andnot);
}

#andnot!(other) ⇒ Object



308
309
310
311
# File 'ext/roaring/bitmap64.c', line 308

static VALUE rb_roaring64_andnot_inplace(VALUE self, VALUE other)
{
    return rb_roaring64_binary_op_inplace(self, other, roaring64_bitmap_andnot_inplace);
}

#cardinalityObject Also known as: size, length, count



65
66
67
68
69
70
# File 'ext/roaring/bitmap64.c', line 65

static VALUE rb_roaring64_cardinality(VALUE self)
{
    roaring64_bitmap_t *data = get_bitmap(self);
    uint64_t cardinality = roaring64_bitmap_get_cardinality(data);
    return ULL2NUM(cardinality);
}

#clearObject



132
133
134
135
136
137
# File 'ext/roaring/bitmap64.c', line 132

static VALUE rb_roaring64_clear(VALUE self)
{
    roaring64_bitmap_t *data = get_bitmap(self);
    roaring64_bitmap_clear(data);
    return self;
}

#disjoint?(other) ⇒ Boolean Originally defined in module BitmapCommon

Returns:

  • (Boolean)

#eachObject



144
145
146
147
148
149
# File 'ext/roaring/bitmap64.c', line 144

static VALUE rb_roaring64_each(VALUE self)
{
    roaring64_bitmap_t *data = get_bitmap(self);
    roaring64_bitmap_iterate(data, rb_roaring64_each_i, NULL);
    return self;
}

#empty?Boolean

Returns:

  • (Boolean)


126
127
128
129
130
# File 'ext/roaring/bitmap64.c', line 126

static VALUE rb_roaring64_empty_p(VALUE self)
{
    roaring64_bitmap_t *data = get_bitmap(self);
    return RBOOL(roaring64_bitmap_is_empty(data));
}

#hashObject Originally defined in module BitmapCommon

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

Returns:

  • (Boolean)


118
119
120
121
122
123
124
# File 'ext/roaring/bitmap64.c', line 118

static VALUE rb_roaring64_include_p(VALUE self, VALUE val)
{
    roaring64_bitmap_t *data = get_bitmap(self);

    uint64_t num = NUM2UINT64(val);
    return RBOOL(roaring64_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:

  • (Boolean)


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

static VALUE rb_roaring64_intersect_p(VALUE self, VALUE other)
{
    return rb_roaring64_binary_op_bool(self, other, roaring64_bitmap_intersect);
}

#maxObject Also known as: last



178
179
180
181
182
183
184
185
186
187
188
# File 'ext/roaring/bitmap64.c', line 178

static VALUE rb_roaring64_max(VALUE self)
{
    roaring64_bitmap_t *data = get_bitmap(self);

    if (roaring64_bitmap_is_empty(data)) {
        return Qnil;
    } else {
        uint64_t val = roaring64_bitmap_maximum(data);
        return ULL2NUM(val);
    }
}

#minObject Also known as: first



166
167
168
169
170
171
172
173
174
175
176
# File 'ext/roaring/bitmap64.c', line 166

static VALUE rb_roaring64_min(VALUE self)
{
    roaring64_bitmap_t *data = get_bitmap(self);

    if (roaring64_bitmap_is_empty(data)) {
        return Qnil;
    } else {
        uint64_t val = roaring64_bitmap_minimum(data);
        return ULL2NUM(val);
    }
}

#or(other) ⇒ Object Also known as: |, +, union



318
319
320
321
# File 'ext/roaring/bitmap64.c', line 318

static VALUE rb_roaring64_or(VALUE self, VALUE other)
{
    return rb_roaring64_binary_op(self, other, roaring64_bitmap_or);
}

#or!(other) ⇒ Object



298
299
300
301
# File 'ext/roaring/bitmap64.c', line 298

static VALUE rb_roaring64_or_inplace(VALUE self, VALUE other)
{
    return rb_roaring64_binary_op_inplace(self, other, roaring64_bitmap_or_inplace);
}

#or_cardinality(other) ⇒ Object



333
334
335
336
# File 'ext/roaring/bitmap64.c', line 333

static VALUE rb_roaring64_or_cardinality(VALUE self, VALUE other)
{
    return rb_roaring64_binary_op_cardinality(self, other, roaring64_bitmap_or_cardinality);
}

#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



101
102
103
104
105
106
107
108
# File 'ext/roaring/bitmap64.c', line 101

static VALUE rb_roaring64_remove(VALUE self, VALUE val)
{
    roaring64_bitmap_t *data = get_bitmap(self);

    uint64_t num = NUM2UINT64(val);
    roaring64_bitmap_remove(data, num);
    return self;
}

#remove?(val) ⇒ Boolean Also known as: delete?

Returns:

  • (Boolean)


110
111
112
113
114
115
116
# File 'ext/roaring/bitmap64.c', line 110

static VALUE rb_roaring64_remove_p(VALUE self, VALUE val)
{
    roaring64_bitmap_t *data = get_bitmap(self);

    uint64_t num = NUM2UINT64(val);
    return roaring64_bitmap_remove_checked(data, num) ? self : Qnil;
}

#replace(other) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
# File 'ext/roaring/bitmap64.c', line 52

static VALUE rb_roaring64_replace(VALUE self, VALUE other) {
    roaring64_bitmap_t *self_data = get_bitmap(self);
    roaring64_bitmap_t *other_data = get_bitmap(other);

    // FIXME: Very likely a newer version of CRoaring will have
    //roaring64_bitmap_overwrite(self_data, other_data);

    roaring64_bitmap_clear(self_data);
    roaring64_bitmap_or_inplace(self_data, other_data);

    return self;
}

#run_optimizeObject



190
191
192
193
194
# File 'ext/roaring/bitmap64.c', line 190

static VALUE rb_roaring64_run_optimize(VALUE self)
{
    roaring64_bitmap_t *data = get_bitmap(self);
    return RBOOL(roaring64_bitmap_run_optimize(data));
}

#serializeObject



196
197
198
199
200
201
202
203
204
205
206
207
# File 'ext/roaring/bitmap64.c', line 196

static VALUE rb_roaring64_serialize(VALUE self)
{
    roaring64_bitmap_t *data = get_bitmap(self);

    size_t size = roaring64_bitmap_portable_size_in_bytes(data);
    VALUE str = rb_str_buf_new(size);

    size_t written = roaring64_bitmap_portable_serialize(data, RSTRING_PTR(str));
    rb_str_set_len(str, written);

    return str;
}

#statisticsObject



223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
# File 'ext/roaring/bitmap64.c', line 223

static VALUE rb_roaring64_statistics(VALUE self)
{
    roaring64_bitmap_t *data = get_bitmap(self);

    roaring64_statistics_t stat;

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



323
324
325
326
# File 'ext/roaring/bitmap64.c', line 323

static VALUE rb_roaring64_xor(VALUE self, VALUE other)
{
    return rb_roaring64_binary_op(self, other, roaring64_bitmap_xor);
}

#xor!(other) ⇒ Object



303
304
305
306
# File 'ext/roaring/bitmap64.c', line 303

static VALUE rb_roaring64_xor_inplace(VALUE self, VALUE other)
{
    return rb_roaring64_binary_op_inplace(self, other, roaring64_bitmap_xor_inplace);
}

#xor_cardinality(other) ⇒ Object



338
339
340
341
# File 'ext/roaring/bitmap64.c', line 338

static VALUE rb_roaring64_xor_cardinality(VALUE self, VALUE other)
{
    return rb_roaring64_binary_op_cardinality(self, other, roaring64_bitmap_xor_cardinality);
}