Class: Roaring::Bitmap
- Inherits:
-
Object
- Object
- Roaring::Bitmap
- Includes:
- Enumerable
- Defined in:
- lib/roaring.rb,
ext/roaring/cext.c
Class Method Summary collapse
Instance Method Summary collapse
- #&(other) ⇒ Object (also: #intersection)
- #-(other) ⇒ Object (also: #difference)
- #<(other) ⇒ Object (also: #proper_subset?)
- #<<(val) ⇒ Object
- #<=(other) ⇒ Object (also: #subset?)
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object (also: #eql?)
- #>(other) ⇒ Object (also: #proper_superset?)
- #>=(other) ⇒ Object (also: #superset?)
- #[](rankv) ⇒ Object
- #^(other) ⇒ Object
- #_dump(level) ⇒ Object
- #add(val) ⇒ Object
- #add?(val) ⇒ Boolean
- #cardinality ⇒ Object (also: #size, #length, #count)
- #clear ⇒ Object
- #disjoint?(other) ⇒ Boolean
-
#each ⇒ Object
iterate till the end.
- #empty? ⇒ Boolean
- #hash ⇒ Object
- #include?(val) ⇒ Boolean (also: #===)
-
#initialize(enum = nil) ⇒ Bitmap
constructor
A new instance of Bitmap.
- #initialize_copy(other) ⇒ Object
- #inspect ⇒ Object
- #intersect?(other) ⇒ Boolean
- #max ⇒ Object (also: #last)
- #min ⇒ Object (also: #first)
- #remove(val) ⇒ Object (also: #delete)
- #remove?(val) ⇒ Boolean (also: #delete?)
- #replace(other) ⇒ Object
- #run_optimize ⇒ Object
- #serialize ⇒ Object
- #to_a ⇒ Object
- #to_set ⇒ Object
- #|(other) ⇒ Object (also: #+, #union)
Constructor Details
Class Method Details
.[](*args) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/roaring.rb', line 51 def self.[](*args) if args.size == 0 new elsif args.size == 1 && !(Integer === args[0]) new(args[0]) else new(args) end end |
._load(args) ⇒ Object
94 95 96 |
# File 'lib/roaring.rb', line 94 def self._load args deserialize(args) end |
.deserialize(str) ⇒ Object
198 199 200 201 202 203 |
# File 'ext/roaring/cext.c', line 198
static VALUE rb_roaring_deserialize(VALUE self, VALUE str)
{
roaring_bitmap_t *bitmap = roaring_bitmap_portable_deserialize_safe(RSTRING_PTR(str), RSTRING_LEN(str));
return TypedData_Wrap_Struct(cRoaringBitmap, &roaring_type, bitmap);
}
|
Instance Method Details
#&(other) ⇒ Object Also known as: intersection
225 226 227 228 |
# File 'ext/roaring/cext.c', line 225
static VALUE rb_roaring_and(VALUE self, VALUE other)
{
return rb_roaring_binary_op(self, other, roaring_bitmap_and);
}
|
#-(other) ⇒ Object Also known as: difference
240 241 242 243 |
# File 'ext/roaring/cext.c', line 240
static VALUE rb_roaring_andnot(VALUE self, VALUE other)
{
return rb_roaring_binary_op(self, other, roaring_bitmap_andnot);
}
|
#<(other) ⇒ Object Also known as: proper_subset?
250 251 252 253 |
# File 'ext/roaring/cext.c', line 250
static VALUE rb_roaring_lt(VALUE self, VALUE other)
{
return rb_roaring_binary_op_bool(self, other, roaring_bitmap_is_strict_subset);
}
|
#<<(val) ⇒ Object
73 74 75 76 77 78 79 80 |
# File 'ext/roaring/cext.c', line 73
static VALUE rb_roaring_add(VALUE self, VALUE val)
{
roaring_bitmap_t *data = get_bitmap(self);
uint32_t num = NUM2UINT32(val);
roaring_bitmap_add(data, num);
return self;
}
|
#<=(other) ⇒ Object Also known as: subset?
255 256 257 258 |
# File 'ext/roaring/cext.c', line 255
static VALUE rb_roaring_lte(VALUE self, VALUE other)
{
return rb_roaring_binary_op_bool(self, other, roaring_bitmap_is_subset);
}
|
#<=>(other) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/roaring.rb', line 74 def <=>(other) if self == other 0 elsif subset?(other) -1 elsif superset?(other) 1 else nil end end |
#==(other) ⇒ Object Also known as: eql?
245 246 247 248 |
# File 'ext/roaring/cext.c', line 245
static VALUE rb_roaring_eq(VALUE self, VALUE other)
{
return rb_roaring_binary_op_bool(self, other, roaring_bitmap_equals);
}
|
#>(other) ⇒ Object Also known as: proper_superset?
61 62 63 |
# File 'lib/roaring.rb', line 61 def >(other) other < self end |
#>=(other) ⇒ Object Also known as: superset?
65 66 67 |
# File 'lib/roaring.rb', line 65 def >=(other) other <= self end |
#[](rankv) ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'ext/roaring/cext.c', line 140
static VALUE rb_roaring_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;
}
|
#^(other) ⇒ Object
235 236 237 238 |
# File 'ext/roaring/cext.c', line 235
static VALUE rb_roaring_xor(VALUE self, VALUE other)
{
return rb_roaring_binary_op(self, other, roaring_bitmap_xor);
}
|
#_dump(level) ⇒ Object
90 91 92 |
# File 'lib/roaring.rb', line 90 def _dump level serialize end |
#add(val) ⇒ Object
73 74 75 76 77 78 79 80 |
# File 'ext/roaring/cext.c', line 73
static VALUE rb_roaring_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
82 83 84 85 86 87 88 |
# File 'ext/roaring/cext.c', line 82
static VALUE rb_roaring_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;
}
|
#cardinality ⇒ Object Also known as: size, length, count
66 67 68 69 70 71 |
# File 'ext/roaring/cext.c', line 66
static VALUE rb_roaring_cardinality(VALUE self)
{
roaring_bitmap_t *data = get_bitmap(self);
uint64_t cardinality = roaring_bitmap_get_cardinality(data);
return ULONG2NUM(cardinality);
}
|
#clear ⇒ Object
121 122 123 124 125 126 |
# File 'ext/roaring/cext.c', line 121
static VALUE rb_roaring_clear(VALUE self)
{
roaring_bitmap_t *data = get_bitmap(self);
roaring_bitmap_clear(data);
return self;
}
|
#disjoint?(other) ⇒ Boolean
86 87 88 |
# File 'lib/roaring.rb', line 86 def disjoint?(other) !intersect?(other) end |
#each ⇒ Object
iterate till the end
133 134 135 136 137 138 |
# File 'ext/roaring/cext.c', line 133
static VALUE rb_roaring_each(VALUE self)
{
roaring_bitmap_t *data = get_bitmap(self);
roaring_iterate(data, rb_roaring_each_i, NULL);
return self;
}
|
#empty? ⇒ Boolean
115 116 117 118 119 |
# File 'ext/roaring/cext.c', line 115
static VALUE rb_roaring_empty_p(VALUE self)
{
roaring_bitmap_t *data = get_bitmap(self);
return RBOOL(roaring_bitmap_is_empty(data));
}
|
#hash ⇒ Object
40 41 42 |
# File 'lib/roaring.rb', line 40 def hash to_a.hash end |
#include?(val) ⇒ Boolean Also known as: ===
107 108 109 110 111 112 113 |
# File 'ext/roaring/cext.c', line 107
static VALUE rb_roaring_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_copy(other) ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'ext/roaring/cext.c', line 57
static VALUE rb_roaring_initialize_copy(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;
}
|
#inspect ⇒ Object
106 107 108 109 110 111 112 113 |
# File 'lib/roaring.rb', line 106 def inspect cardinality = self.cardinality if cardinality < 64 "#<#{self.class} {#{to_a.join(", ")}}>" else "#<#{self.class} (#{cardinality} values)>" end end |
#intersect?(other) ⇒ Boolean
260 261 262 263 |
# File 'ext/roaring/cext.c', line 260
static VALUE rb_roaring_intersect_p(VALUE self, VALUE other)
{
return rb_roaring_binary_op_bool(self, other, roaring_bitmap_intersect);
}
|
#max ⇒ Object Also known as: last
167 168 169 170 171 172 173 174 175 176 177 |
# File 'ext/roaring/cext.c', line 167
static VALUE rb_roaring_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 ⇒ Object Also known as: first
155 156 157 158 159 160 161 162 163 164 165 |
# File 'ext/roaring/cext.c', line 155
static VALUE rb_roaring_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);
}
}
|
#remove(val) ⇒ Object Also known as: delete
90 91 92 93 94 95 96 97 |
# File 'ext/roaring/cext.c', line 90
static VALUE rb_roaring_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) ⇒ Boolean Also known as: delete?
99 100 101 102 103 104 105 |
# File 'ext/roaring/cext.c', line 99
static VALUE rb_roaring_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
46 47 48 49 |
# File 'lib/roaring.rb', line 46 def replace(other) # FIXME: this should probably be initialize_copy and replace should be in C initialize_copy(other) end |
#run_optimize ⇒ Object
179 180 181 182 183 |
# File 'ext/roaring/cext.c', line 179
static VALUE rb_roaring_run_optimize(VALUE self)
{
roaring_bitmap_t *data = get_bitmap(self);
return RBOOL(roaring_bitmap_run_optimize(data));
}
|
#serialize ⇒ Object
185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'ext/roaring/cext.c', line 185
static VALUE rb_roaring_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;
}
|
#to_a ⇒ Object
98 99 100 |
# File 'lib/roaring.rb', line 98 def to_a map(&:itself) end |
#to_set ⇒ Object
102 103 104 |
# File 'lib/roaring.rb', line 102 def to_set ::Set.new(to_a) end |
#|(other) ⇒ Object Also known as: +, union
230 231 232 233 |
# File 'ext/roaring/cext.c', line 230
static VALUE rb_roaring_or(VALUE self, VALUE other)
{
return rb_roaring_binary_op(self, other, roaring_bitmap_or);
}
|