Class: Roaring::Bitmap64

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

Methods included from BitmapCommon

#<=>, #>, #>=, #_dump, #disjoint?, #hash, included, #initialize, #initialize_copy, #inspect, #to_a, #to_set

Class Method Details

.deserialize(str) ⇒ Object



198
199
200
201
202
203
# File 'ext/roaring/bitmap64.c', line 198

static VALUE rb_roaring64_deserialize(VALUE self, VALUE str)
{
    roaring64_bitmap_t *bitmap = roaring64_bitmap_portable_deserialize_safe(RSTRING_PTR(str), RSTRING_LEN(str));

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

Instance Method Details

#&(other) ⇒ Object



225
226
227
228
# File 'ext/roaring/bitmap64.c', line 225

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

#-(other) ⇒ Object



240
241
242
243
# File 'ext/roaring/bitmap64.c', line 240

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

#<(other) ⇒ Object



250
251
252
253
# File 'ext/roaring/bitmap64.c', line 250

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

#<<(val) ⇒ Object



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

#<=(other) ⇒ Object



255
256
257
258
# File 'ext/roaring/bitmap64.c', line 255

static VALUE rb_roaring64_lte(VALUE self, VALUE other)
{
    return rb_roaring64_binary_op_bool(self, other, roaring64_bitmap_is_subset);
}

#==(other) ⇒ Object



245
246
247
248
# File 'ext/roaring/bitmap64.c', line 245

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

#[](rankv) ⇒ Object



140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'ext/roaring/bitmap64.c', line 140

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

#^(other) ⇒ Object



235
236
237
238
# File 'ext/roaring/bitmap64.c', line 235

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

#add(val) ⇒ Object



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

#cardinalityObject



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 ULONG2NUM(cardinality);
}

#clearObject



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

static VALUE rb_roaring64_clear(VALUE self)
{
    roaring64_bitmap_t *data = get_bitmap(self);
    // roaring64_bitmap_clear(data); // Doesn't exist yet in 4.0.0
    roaring64_bitmap_remove_range_closed(data, 0, UINT64_MAX);
    return self;
}

#eachObject

iterate till the end



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

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)


114
115
116
117
118
# File 'ext/roaring/bitmap64.c', line 114

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

#include?(val) ⇒ Boolean

Returns:

  • (Boolean)


106
107
108
109
110
111
112
# File 'ext/roaring/bitmap64.c', line 106

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

#intersect?(other) ⇒ Boolean

Returns:

  • (Boolean)


260
261
262
263
# File 'ext/roaring/bitmap64.c', line 260

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

#maxObject



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

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



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

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

#remove(val) ⇒ Object



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

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

Returns:

  • (Boolean)


98
99
100
101
102
103
104
# File 'ext/roaring/bitmap64.c', line 98

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_remove_range_closed(self_data, 0, UINT64_MAX);
    roaring64_bitmap_or_inplace(self_data, other_data);

    return self;
}

#run_optimizeObject



179
180
181
182
183
# File 'ext/roaring/bitmap64.c', line 179

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

#serializeObject



185
186
187
188
189
190
191
192
193
194
195
196
# File 'ext/roaring/bitmap64.c', line 185

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

#|(other) ⇒ Object



230
231
232
233
# File 'ext/roaring/bitmap64.c', line 230

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