Module: Roaring::BitmapCommon

Includes:
Enumerable
Included in:
Bitmap32, Bitmap64
Defined in:
lib/roaring.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#<=>(other) ⇒ 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.

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.



134
135
136
137
138
139
140
141
142
143
144
# File 'lib/roaring.rb', line 134

def <=>(other)
  if self == other
    0
  elsif subset?(other)
    -1
  elsif superset?(other)
    1
  else
    nil
  end
end

#_dump(level) ⇒ Object



150
151
152
# File 'lib/roaring.rb', line 150

def _dump level
  serialize
end

#add_range(min, max) ⇒ Object



128
129
130
131
# File 'lib/roaring.rb', line 128

def add_range(min, max)
  return if max <= min
  add_range_closed(min, max - 1)
end

#disjoint?(other) ⇒ Boolean

Returns:

  • (Boolean)


146
147
148
# File 'lib/roaring.rb', line 146

def disjoint?(other)
  !intersect?(other)
end

#hashObject



105
106
107
# File 'lib/roaring.rb', line 105

def hash
  to_a.hash
end

#initialize(enum = nil) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/roaring.rb', line 89

def initialize(enum = nil)
  return unless enum

  if enum.instance_of?(self.class)
    replace(enum)
  elsif Range === enum
    if enum.exclude_end?
      add_range(enum.begin, enum.end)
    else
      add_range_closed(enum.begin, enum.end)
    end
  else
    enum.each { |x| self << x }
  end
end

#initialize_copy(other) ⇒ Object



109
110
111
# File 'lib/roaring.rb', line 109

def initialize_copy(other)
  replace(other)
end

#inspectString

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



163
164
165
166
167
168
169
170
# File 'lib/roaring.rb', line 163

def inspect
  cardinality = self.cardinality
  if cardinality < 64
    "#<#{self.class} {#{to_a.join(", ")}}>"
  else
    "#<#{self.class} (#{cardinality} values)>"
  end
end

#proper_superset?(other) ⇒ Boolean Also known as: >

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`



121
122
123
# File 'lib/roaring.rb', line 121

def proper_superset?(other)
  other < self
end

#superset?(other) ⇒ Boolean Also known as: >=

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`



115
116
117
# File 'lib/roaring.rb', line 115

def superset?(other)
  other <= self
end

#to_setObject



154
155
156
# File 'lib/roaring.rb', line 154

def to_set
  ::Set.new(self)
end