roaring 0.3.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/roaring.rb CHANGED
@@ -1,44 +1,74 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "roaring/version"
4
- require_relative "roaring/roaring"
4
+ require "roaring/roaring"
5
5
  require "set"
6
6
 
7
7
  module Roaring
8
8
  class Error < StandardError; end
9
9
 
10
10
  module BitmapCommon
11
- def self.included(base)
12
- super
13
-
14
- base.extend ClassMethods
15
-
16
- base.alias_method :size, :cardinality
17
- base.alias_method :length, :cardinality
18
- base.alias_method :count, :cardinality
19
-
20
- base.alias_method :+, :|
21
- base.alias_method :union, :|
22
- base.alias_method :intersection, :&
23
- base.alias_method :difference, :-
24
-
25
- base.alias_method :delete, :remove
26
- base.alias_method :delete?, :remove?
27
-
28
- base.alias_method :first, :min
29
- base.alias_method :last, :max
30
-
31
- base.alias_method :eql?, :==
32
-
33
- base.alias_method :===, :include?
34
-
35
- base.alias_method :subset?, :<=
36
- base.alias_method :proper_subset?, :<
37
- base.alias_method :superset?, :>=
38
- base.alias_method :proper_superset?, :>
39
- end
40
-
41
11
  module ClassMethods
12
+ # @private
13
+ # @!macro [attach] property
14
+ # @!parse alias_method :<<, :add
15
+ #
16
+ # @!parse alias_method :size, :cardinality
17
+ # @!parse alias_method :length, :cardinality
18
+ # @!parse alias_method :count, :cardinality
19
+ #
20
+ # @!parse alias_method :&, :and
21
+ # @!parse alias_method :|, :or
22
+ # @!parse alias_method :^, :xor
23
+ # @!parse alias_method :-, :andnot
24
+ # @!parse alias_method :+, :or
25
+ # @!parse alias_method :union, :or
26
+ # @!parse alias_method :intersection, :and
27
+ # @!parse alias_method :difference, :andnot
28
+ #
29
+ # @!parse alias_method :delete, :remove
30
+ # @!parse alias_method :delete?, :remove?
31
+ #
32
+ # @!parse alias_method :first, :min
33
+ # @!parse alias_method :last, :max
34
+ #
35
+ # @!parse alias_method :eql?, :==
36
+ #
37
+ # @!parse alias_method :===, :include?
38
+ #
39
+ # @!parse alias_method :subset?, :<=
40
+ # @!parse alias_method :proper_subset?, :<
41
+ def define_roaring_aliases!
42
+ alias_method :<<, :add
43
+
44
+ alias_method :size, :cardinality
45
+ alias_method :length, :cardinality
46
+ alias_method :count, :cardinality
47
+
48
+ alias_method :&, :and
49
+ alias_method :|, :or
50
+ alias_method :^, :xor
51
+ alias_method :-, :andnot
52
+ alias_method :+, :or
53
+ alias_method :union, :or
54
+ alias_method :intersection, :and
55
+ alias_method :difference, :andnot
56
+
57
+ alias_method :delete, :remove
58
+ alias_method :delete?, :remove?
59
+
60
+ alias_method :first, :min
61
+ alias_method :last, :max
62
+
63
+ alias_method :eql?, :==
64
+
65
+ alias_method :===, :include?
66
+
67
+ alias_method :subset?, :<=
68
+ alias_method :proper_subset?, :<
69
+ end
70
+
71
+ # Convenience method for building a bitmap
42
72
  def [](*args)
43
73
  if args.size == 0
44
74
  new
@@ -61,6 +91,12 @@ module Roaring
61
91
 
62
92
  if enum.instance_of?(self.class)
63
93
  replace(enum)
94
+ elsif Range === enum
95
+ if enum.exclude_end?
96
+ add_range(enum.begin, enum.end)
97
+ else
98
+ add_range_closed(enum.begin, enum.end)
99
+ end
64
100
  else
65
101
  enum.each { |x| self << x }
66
102
  end
@@ -74,14 +110,27 @@ module Roaring
74
110
  replace(other)
75
111
  end
76
112
 
77
- def >(other)
113
+ # Check if `self` is a superset of `other`. A superset requires that `self` contain all of `other`'s elemtents. They may be equal.
114
+ # @return [Boolean] `true` if `self` is a strict subset of `other`, otherwise `false`
115
+ def superset?(other)
116
+ other <= self
117
+ end
118
+
119
+ # 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.
120
+ # @return [Boolean] `true` if `self` is a strict subset of `other`, otherwise `false`
121
+ def proper_superset?(other)
78
122
  other < self
79
123
  end
80
124
 
81
- def >=(other)
82
- other <= self
125
+ alias_method :>=, :superset?
126
+ alias_method :>, :proper_superset?
127
+
128
+ def add_range(min, max)
129
+ return if max <= min
130
+ add_range_closed(min, max - 1)
83
131
  end
84
132
 
133
+ # @return [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.
85
134
  def <=>(other)
86
135
  if self == other
87
136
  0
@@ -102,14 +151,15 @@ module Roaring
102
151
  serialize
103
152
  end
104
153
 
105
- def to_a
106
- map(&:itself)
107
- end
108
-
109
154
  def to_set
110
- ::Set.new(to_a)
155
+ ::Set.new(self)
111
156
  end
112
157
 
158
+ # @example Small bitmap
159
+ # Roaring::Bitmap32[1,2,3].inspect #=> "#<Roaring::Bitmap32 {1, 2, 3}>"
160
+ # @example Large bitmap
161
+ # Roaring::Bitmap32[1..1000].inspect #=> "#<Roaring::Bitmap32 (1000 values)>"
162
+ # @return [String] a programmer-readable representation of the bitmap
113
163
  def inspect
114
164
  cardinality = self.cardinality
115
165
  if cardinality < 64
@@ -122,6 +172,9 @@ module Roaring
122
172
 
123
173
  class Bitmap32
124
174
  include BitmapCommon
175
+ extend BitmapCommon::ClassMethods
176
+
177
+ define_roaring_aliases!
125
178
 
126
179
  MIN = 0
127
180
  MAX = (2**32) - 1
@@ -130,6 +183,9 @@ module Roaring
130
183
 
131
184
  class Bitmap64
132
185
  include BitmapCommon
186
+ extend BitmapCommon::ClassMethods
187
+
188
+ define_roaring_aliases!
133
189
 
134
190
  MIN = 0
135
191
  MAX = (2**64) - 1
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roaring
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Hawthorn
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2024-06-12 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: prime
@@ -32,12 +31,14 @@ extensions:
32
31
  - ext/roaring/extconf.rb
33
32
  extra_rdoc_files: []
34
33
  files:
34
+ - ".yardopts"
35
35
  - CODE_OF_CONDUCT.md
36
36
  - Gemfile
37
- - Gemfile.lock
38
37
  - LICENSE.txt
39
38
  - README.md
40
39
  - Rakefile
40
+ - benchmark/to_a.rb
41
+ - benchmark/to_set.rb
41
42
  - ext/roaring/bitmap32.c
42
43
  - ext/roaring/bitmap64.c
43
44
  - ext/roaring/cext.c
@@ -56,7 +57,6 @@ metadata:
56
57
  homepage_uri: https://github.com/jhawthorn/roaring-ruby
57
58
  changelog_uri: https://github.com/jhawthorn/roaring-ruby
58
59
  source_code_uri: https://github.com/jhawthorn/roaring-ruby
59
- post_install_message:
60
60
  rdoc_options: []
61
61
  require_paths:
62
62
  - lib
@@ -71,8 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
71
  - !ruby/object:Gem::Version
72
72
  version: '0'
73
73
  requirements: []
74
- rubygems_version: 3.5.9
75
- signing_key:
74
+ rubygems_version: 4.0.10
76
75
  specification_version: 4
77
76
  summary: Roaring bitmaps for Ruby
78
77
  test_files: []
data/Gemfile.lock DELETED
@@ -1,39 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- roaring (0.3.0)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
- debug (1.6.2)
10
- irb (>= 1.3.6)
11
- reline (>= 0.3.1)
12
- forwardable (1.3.2)
13
- io-console (0.5.11)
14
- irb (1.4.1)
15
- reline (>= 0.3.0)
16
- minitest (5.16.3)
17
- prime (0.1.2)
18
- forwardable
19
- singleton
20
- rake (13.0.6)
21
- rake-compiler (1.2.0)
22
- rake
23
- reline (0.3.1)
24
- io-console (~> 0.5)
25
- singleton (0.1.1)
26
-
27
- PLATFORMS
28
- x86_64-linux
29
-
30
- DEPENDENCIES
31
- debug
32
- minitest (~> 5.0)
33
- prime
34
- rake (~> 13.0)
35
- rake-compiler
36
- roaring!
37
-
38
- BUNDLED WITH
39
- 2.3.4