Module: Roaring::BitmapCommon

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

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/roaring.rb', line 11

def self.included(base)
  super

  base.extend ClassMethods

  base.alias_method :size, :cardinality
  base.alias_method :length, :cardinality
  base.alias_method :count, :cardinality

  base.alias_method :+, :|
  base.alias_method :union, :|
  base.alias_method :intersection, :&
  base.alias_method :difference, :-

  base.alias_method :delete, :remove
  base.alias_method :delete?, :remove?

  base.alias_method :first, :min
  base.alias_method :last, :max

  base.alias_method :eql?, :==

  base.alias_method :===, :include?

  base.alias_method :subset?, :<=
  base.alias_method :proper_subset?, :<
  base.alias_method :superset?, :>=
  base.alias_method :proper_superset?, :>
end

Instance Method Details

#<=>(other) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
# File 'lib/roaring.rb', line 85

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

#>(other) ⇒ Object



77
78
79
# File 'lib/roaring.rb', line 77

def >(other)
  other < self
end

#>=(other) ⇒ Object



81
82
83
# File 'lib/roaring.rb', line 81

def >=(other)
  other <= self
end

#_dump(level) ⇒ Object



101
102
103
# File 'lib/roaring.rb', line 101

def _dump level
  serialize
end

#disjoint?(other) ⇒ Boolean

Returns:

  • (Boolean)


97
98
99
# File 'lib/roaring.rb', line 97

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

#hashObject



69
70
71
# File 'lib/roaring.rb', line 69

def hash
  to_a.hash
end

#initialize(enum = nil) ⇒ Object



59
60
61
62
63
64
65
66
67
# File 'lib/roaring.rb', line 59

def initialize(enum = nil)
  return unless enum

  if enum.instance_of?(self.class)
    replace(enum)
  else
    enum.each { |x| self << x }
  end
end

#initialize_copy(other) ⇒ Object



73
74
75
# File 'lib/roaring.rb', line 73

def initialize_copy(other)
  replace(other)
end

#inspectObject



113
114
115
116
117
118
119
120
# File 'lib/roaring.rb', line 113

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

#to_aObject



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

def to_a
  map(&:itself)
end

#to_setObject



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

def to_set
  ::Set.new(to_a)
end