Module: Roaring::BitmapCommon
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#<=>(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.
- #_dump(level) ⇒ Object
- #add_range(min, max) ⇒ Object
- #disjoint?(other) ⇒ Boolean
- #hash ⇒ Object
- #initialize(enum = nil) ⇒ Object
- #initialize_copy(other) ⇒ Object
-
#inspect ⇒ String
A programmer-readable representation of the bitmap.
-
#proper_superset?(other) ⇒ Boolean
(also: #>)
Check if ‘self` is a strict superset of `other`.
-
#superset?(other) ⇒ Boolean
(also: #>=)
Check if ‘self` is a superset of `other`.
- #to_set ⇒ Object
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.
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
146 147 148 |
# File 'lib/roaring.rb', line 146 def disjoint?(other) !intersect?(other) end |
#hash ⇒ Object
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 |
#inspect ⇒ String
Returns 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.
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.
115 116 117 |
# File 'lib/roaring.rb', line 115 def superset?(other) other <= self end |
#to_set ⇒ Object
154 155 156 |
# File 'lib/roaring.rb', line 154 def to_set ::Set.new(self) end |