set 1.0.2 → 1.1.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f64668b1687c9f23c7f608baba3bd5b2455d2d56e435840a547742640f5ced35
4
- data.tar.gz: 72306f090587dd7a667445e7adaa443c07dae10a067e851d5dcb045d49fa9165
3
+ metadata.gz: cef560e603f6d6413751c31bb94fddf3838a66af8e71cff73c74760ff479ff6a
4
+ data.tar.gz: 448e22e93eebe57b26200fc1c8be476d60494193136aabb09a50c68e878e96cf
5
5
  SHA512:
6
- metadata.gz: 831b03fe1e1ec4c74188fa91f224411d645aab6cd64d99cb499d1e62a4c0f2c3f660bfc6709c4ace1fdec336b5aae3b32691f70262bc9023cbd427a6a1934b8b
7
- data.tar.gz: 28da11f61439186d2dc7cc091101884fbd1346489720505bcd1dc507c9933893b477696d04c0a832ac26a103cdad9f634b328c3280504fe4ecf7e44e35a75c52
6
+ metadata.gz: 91fa3052d7f25eaf6c0066013a5bd2d0c58961fe330c8923853634bac908ae83323d01b26ec8f85c4ab1ae309a83cc8e30e0918802ebb6f96fc3fcb7b7bdd433
7
+ data.tar.gz: 07b57081279057d476e1fe7c07587db1de0243cb78d36bc04b5b3ed303643b54320f08e98ed3672e610df84c42f0d503c7fae7eba040d2cf260c84319e7f9745
@@ -0,0 +1 @@
1
+ * @knu
@@ -0,0 +1,6 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: 'github-actions'
4
+ directory: '/'
5
+ schedule:
6
+ interval: 'weekly'
@@ -7,11 +7,11 @@ jobs:
7
7
  name: build (${{ matrix.ruby }} / ${{ matrix.os }})
8
8
  strategy:
9
9
  matrix:
10
- ruby: [ 2.7, 2.6, 2.5, head ]
10
+ ruby: [ 3.2, 3.1, "3.0", head ]
11
11
  os: [ ubuntu-latest, macos-latest ]
12
12
  runs-on: ${{ matrix.os }}
13
13
  steps:
14
- - uses: actions/checkout@v2
14
+ - uses: actions/checkout@v4
15
15
  - name: Set up Ruby
16
16
  uses: ruby/setup-ruby@v1
17
17
  with:
data/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # Set Changelog
2
2
 
3
+ # 1.1.0 (2023-12-23)
4
+
5
+ * Optimize for and require Ruby >=3
6
+
7
+ # 1.0.4 (2023-12-08)
8
+
9
+ * Enhancements
10
+ * Avoid the `block or return` pattern to save Proc allocations [#29][] ([@casperisfine][])
11
+ * Set#merge takes many enumerable objects [#30][]
12
+
13
+ # 1.0.3 (2022-09-06)
14
+
15
+ * Enhancements
16
+ * Make Set a builtin feature \[[Feature #16989][]]
17
+
3
18
  # 1.0.2 (2021-10-25)
4
19
 
5
20
  * Enhancements
@@ -31,9 +46,13 @@ This is the first release of set as a gem. Here lists the changes since the ver
31
46
  [#17]: https://github.com/ruby/set/pull/17
32
47
  [#18]: https://github.com/ruby/set/pull/18
33
48
  [#20]: https://github.com/ruby/set/pull/20
49
+ [#29]: https://github.com/ruby/set/pull/29
50
+ [#30]: https://github.com/ruby/set/pull/30
34
51
  [Feature #17838]: https://bugs.ruby-lang.org/issues/17838
52
+ [Feature #16989]: https://bugs.ruby-lang.org/issues/16989
35
53
 
36
54
  [@BurdetteLamar]: https://github.com/BurdetteLamar
55
+ [@casperisfine]: https://github.com/casperisfine
37
56
  [@jeremyevans]: https://github.com/jeremyevans
38
57
  [@k-tsj]: https://github.com/k-tsj
39
58
  [@knu]: https://github.com/knu
data/lib/set.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # set.rb - defines the Set class
5
5
  #
6
- # Copyright (c) 2002-2020 Akinori MUSHA <knu@iDaemons.org>
6
+ # Copyright (c) 2002-2023 Akinori MUSHA <knu@iDaemons.org>
7
7
  #
8
8
  # Documentation by Akinori MUSHA and Gavin Sinclair.
9
9
  #
@@ -12,16 +12,12 @@
12
12
 
13
13
 
14
14
  ##
15
- # This library provides the Set class, which deals with a collection
16
- # of unordered values with no duplicates. It is a hybrid of Array's
15
+ # This library provides the Set class, which implements a collection
16
+ # of unordered values with no duplicates. It is a hybrid of Array's
17
17
  # intuitive inter-operation facilities and Hash's fast lookup.
18
18
  #
19
19
  # The method `to_set` is added to Enumerable for convenience.
20
20
  #
21
- # Set implements a collection of unordered values with no duplicates.
22
- # This is a hybrid of Array's intuitive inter-operation facilities and
23
- # Hash's fast lookup.
24
- #
25
21
  # Set is easy to use with Enumerable objects (implementing `each`).
26
22
  # Most of the initializer methods and binary operators accept generic
27
23
  # Enumerable objects besides sets and arrays. An Enumerable object
@@ -88,138 +84,140 @@
88
84
  #
89
85
  # ### Methods for Creating a \Set
90
86
  #
91
- # - ::[] -
87
+ # - ::[]:
92
88
  # Returns a new set containing the given objects.
93
- # - ::new -
89
+ # - ::new:
94
90
  # Returns a new set containing either the given objects
95
91
  # (if no block given) or the return values from the called block
96
92
  # (if a block given).
97
93
  #
98
94
  # ### Methods for \Set Operations
99
95
  #
100
- # - [|](#method-i-7C) (aliased as #union and #+) -
96
+ # - [|](#method-i-7C) (aliased as #union and #+):
101
97
  # Returns a new set containing all elements from +self+
102
98
  # and all elements from a given enumerable (no duplicates).
103
- # - [&](#method-i-26) (aliased as #intersection) -
99
+ # - [&](#method-i-26) (aliased as #intersection):
104
100
  # Returns a new set containing all elements common to +self+
105
101
  # and a given enumerable.
106
- # - [-](#method-i-2D) (aliased as #difference) -
102
+ # - [-](#method-i-2D) (aliased as #difference):
107
103
  # Returns a copy of +self+ with all elements
108
104
  # in a given enumerable removed.
109
- # - [\^](#method-i-5E) -
105
+ # - [\^](#method-i-5E):
110
106
  # Returns a new set containing all elements from +self+
111
107
  # and a given enumerable except those common to both.
112
108
  #
113
109
  # ### Methods for Comparing
114
110
  #
115
- # - [<=>](#method-i-3C-3D-3E) -
111
+ # - [<=>](#method-i-3C-3D-3E):
116
112
  # Returns -1, 0, or 1 as +self+ is less than, equal to,
117
113
  # or greater than a given object.
118
- # - [==](#method-i-3D-3D) -
114
+ # - [==](#method-i-3D-3D):
119
115
  # Returns whether +self+ and a given enumerable are equal,
120
116
  # as determined by Object#eql?.
121
- # - \#compare_by_identity? -
117
+ # - \#compare_by_identity?:
122
118
  # Returns whether the set considers only identity
123
119
  # when comparing elements.
124
120
  #
125
121
  # ### Methods for Querying
126
122
  #
127
- # - \#length (aliased as #size) -
123
+ # - \#length (aliased as #size):
128
124
  # Returns the count of elements.
129
- # - \#empty? -
125
+ # - \#empty?:
130
126
  # Returns whether the set has no elements.
131
- # - \#include? (aliased as #member? and #===) -
127
+ # - \#include? (aliased as #member? and #===):
132
128
  # Returns whether a given object is an element in the set.
133
- # - \#subset? (aliased as [<=](#method-i-3C-3D)) -
129
+ # - \#subset? (aliased as [<=](#method-i-3C-3D)):
134
130
  # Returns whether a given object is a subset of the set.
135
- # - \#proper_subset? (aliased as [<](#method-i-3C)) -
131
+ # - \#proper_subset? (aliased as [<](#method-i-3C)):
136
132
  # Returns whether a given enumerable is a proper subset of the set.
137
- # - \#superset? (aliased as [<=](#method-i-3E-3D])) -
133
+ # - \#superset? (aliased as [>=](#method-i-3E-3D])):
138
134
  # Returns whether a given enumerable is a superset of the set.
139
- # - \#proper_superset? (aliased as [>](#method-i-3E)) -
135
+ # - \#proper_superset? (aliased as [>](#method-i-3E)):
140
136
  # Returns whether a given enumerable is a proper superset of the set.
141
- # - \#disjoint? -
137
+ # - \#disjoint?:
142
138
  # Returns +true+ if the set and a given enumerable
143
139
  # have no common elements, +false+ otherwise.
144
- # - \#intersect? -
145
- # Returns +true+ if the set and a given enumerable -
140
+ # - \#intersect?:
141
+ # Returns +true+ if the set and a given enumerable:
146
142
  # have any common elements, +false+ otherwise.
147
- # - \#compare_by_identity? -
143
+ # - \#compare_by_identity?:
148
144
  # Returns whether the set considers only identity
149
145
  # when comparing elements.
150
146
  #
151
147
  # ### Methods for Assigning
152
148
  #
153
- # - \#add (aliased as #<<) -
149
+ # - \#add (aliased as #<<):
154
150
  # Adds a given object to the set; returns +self+.
155
- # - \#add? -
151
+ # - \#add?:
156
152
  # If the given object is not an element in the set,
157
153
  # adds it and returns +self+; otherwise, returns +nil+.
158
- # - \#merge -
159
- # Adds each given object to the set; returns +self+.
160
- # - \#replace -
154
+ # - \#merge:
155
+ # Merges the elements of each given enumerable object to the set; returns +self+.
156
+ # - \#replace:
161
157
  # Replaces the contents of the set with the contents
162
158
  # of a given enumerable.
163
159
  #
164
160
  # ### Methods for Deleting
165
161
  #
166
- # - \#clear -
162
+ # - \#clear:
167
163
  # Removes all elements in the set; returns +self+.
168
- # - \#delete -
164
+ # - \#delete:
169
165
  # Removes a given object from the set; returns +self+.
170
- # - \#delete? -
166
+ # - \#delete?:
171
167
  # If the given object is an element in the set,
172
168
  # removes it and returns +self+; otherwise, returns +nil+.
173
- # - \#subtract -
169
+ # - \#subtract:
174
170
  # Removes each given object from the set; returns +self+.
175
171
  # - \#delete_if - Removes elements specified by a given block.
176
- # - \#select! (aliased as #filter!) -
172
+ # - \#select! (aliased as #filter!):
177
173
  # Removes elements not specified by a given block.
178
- # - \#keep_if -
174
+ # - \#keep_if:
179
175
  # Removes elements not specified by a given block.
180
176
  # - \#reject!
181
177
  # Removes elements specified by a given block.
182
178
  #
183
179
  # ### Methods for Converting
184
180
  #
185
- # - \#classify -
181
+ # - \#classify:
186
182
  # Returns a hash that classifies the elements,
187
183
  # as determined by the given block.
188
- # - \#collect! (aliased as #map!) -
184
+ # - \#collect! (aliased as #map!):
189
185
  # Replaces each element with a block return-value.
190
- # - \#divide -
186
+ # - \#divide:
191
187
  # Returns a hash that classifies the elements,
192
188
  # as determined by the given block;
193
189
  # differs from #classify in that the block may accept
194
190
  # either one or two arguments.
195
- # - \#flatten -
191
+ # - \#flatten:
196
192
  # Returns a new set that is a recursive flattening of +self+.
197
- # \#flatten! -
193
+ # \#flatten!:
198
194
  # Replaces each nested set in +self+ with the elements from that set.
199
- # - \#inspect (aliased as #to_s) -
195
+ # - \#inspect (aliased as #to_s):
200
196
  # Returns a string displaying the elements.
201
- # - \#join -
197
+ # - \#join:
202
198
  # Returns a string containing all elements, converted to strings
203
199
  # as needed, and joined by the given record separator.
204
- # - \#to_a -
200
+ # - \#to_a:
205
201
  # Returns an array containing all set elements.
206
- # - \#to_set -
202
+ # - \#to_set:
207
203
  # Returns +self+ if given no arguments and no block;
208
204
  # with a block given, returns a new set consisting of block
209
205
  # return values.
210
206
  #
211
207
  # ### Methods for Iterating
212
208
  #
213
- # - \#each -
209
+ # - \#each:
214
210
  # Calls the block with each successive element; returns +self+.
215
211
  #
216
212
  # ### Other Methods
217
213
  #
218
- # - \#reset -
214
+ # - \#reset:
219
215
  # Resets the internal state; useful if an object
220
216
  # has been modified while an element in the set.
221
217
  #
222
218
  class Set
219
+ VERSION = "1.1.0"
220
+
223
221
  include Enumerable
224
222
 
225
223
  # Creates a new set containing the given objects.
@@ -288,18 +286,10 @@ class Set
288
286
  @hash = orig.instance_variable_get(:@hash).dup
289
287
  end
290
288
 
291
- if Kernel.instance_method(:initialize_clone).arity != 1
292
- # Clone internal hash.
293
- def initialize_clone(orig, **options)
294
- super
295
- @hash = orig.instance_variable_get(:@hash).clone(**options)
296
- end
297
- else
298
- # Clone internal hash.
299
- def initialize_clone(orig)
300
- super
301
- @hash = orig.instance_variable_get(:@hash).clone
302
- end
289
+ # Clone internal hash.
290
+ def initialize_clone(orig, **options)
291
+ super
292
+ @hash = orig.instance_variable_get(:@hash).clone(**options)
303
293
  end
304
294
 
305
295
  def freeze # :nodoc:
@@ -391,7 +381,7 @@ class Set
391
381
  # Equivalent to Set#flatten, but replaces the receiver with the
392
382
  # result in place. Returns nil if no modifications were made.
393
383
  def flatten!
394
- replace(flatten()) if any? { |e| e.is_a?(Set) }
384
+ replace(flatten()) if any?(Set)
395
385
  end
396
386
 
397
387
  # Returns true if the set contains the given object.
@@ -411,7 +401,7 @@ class Set
411
401
  when set.instance_of?(self.class) && @hash.respond_to?(:>=)
412
402
  @hash >= set.instance_variable_get(:@hash)
413
403
  when set.is_a?(Set)
414
- size >= set.size && set.all? { |o| include?(o) }
404
+ size >= set.size && set.all?(self)
415
405
  else
416
406
  raise ArgumentError, "value must be a set"
417
407
  end
@@ -424,7 +414,7 @@ class Set
424
414
  when set.instance_of?(self.class) && @hash.respond_to?(:>)
425
415
  @hash > set.instance_variable_get(:@hash)
426
416
  when set.is_a?(Set)
427
- size > set.size && set.all? { |o| include?(o) }
417
+ size > set.size && set.all?(self)
428
418
  else
429
419
  raise ArgumentError, "value must be a set"
430
420
  end
@@ -437,7 +427,7 @@ class Set
437
427
  when set.instance_of?(self.class) && @hash.respond_to?(:<=)
438
428
  @hash <= set.instance_variable_get(:@hash)
439
429
  when set.is_a?(Set)
440
- size <= set.size && all? { |o| set.include?(o) }
430
+ size <= set.size && all?(set)
441
431
  else
442
432
  raise ArgumentError, "value must be a set"
443
433
  end
@@ -450,7 +440,7 @@ class Set
450
440
  when set.instance_of?(self.class) && @hash.respond_to?(:<)
451
441
  @hash < set.instance_variable_get(:@hash)
452
442
  when set.is_a?(Set)
453
- size < set.size && all? { |o| set.include?(o) }
443
+ size < set.size && all?(set)
454
444
  else
455
445
  raise ArgumentError, "value must be a set"
456
446
  end
@@ -481,12 +471,12 @@ class Set
481
471
  case set
482
472
  when Set
483
473
  if size < set.size
484
- any? { |o| set.include?(o) }
474
+ any?(set)
485
475
  else
486
- set.any? { |o| include?(o) }
476
+ set.any?(self)
487
477
  end
488
478
  when Enumerable
489
- set.any? { |o| include?(o) }
479
+ set.any?(self)
490
480
  else
491
481
  raise ArgumentError, "value must be enumerable"
492
482
  end
@@ -507,7 +497,7 @@ class Set
507
497
  # the element as parameter. Returns an enumerator if no block is
508
498
  # given.
509
499
  def each(&block)
510
- block or return enum_for(__method__) { size }
500
+ block_given? or return enum_for(__method__) { size }
511
501
  @hash.each_key(&block)
512
502
  self
513
503
  end
@@ -582,7 +572,7 @@ class Set
582
572
  # Equivalent to Set#delete_if, but returns nil if no changes were
583
573
  # made. Returns an enumerator if no block is given.
584
574
  def reject!(&block)
585
- block or return enum_for(__method__) { size }
575
+ block_given? or return enum_for(__method__) { size }
586
576
  n = size
587
577
  delete_if(&block)
588
578
  self if size != n
@@ -591,7 +581,7 @@ class Set
591
581
  # Equivalent to Set#keep_if, but returns nil if no changes were
592
582
  # made. Returns an enumerator if no block is given.
593
583
  def select!(&block)
594
- block or return enum_for(__method__) { size }
584
+ block_given? or return enum_for(__method__) { size }
595
585
  n = size
596
586
  keep_if(&block)
597
587
  self if size != n
@@ -600,13 +590,15 @@ class Set
600
590
  # Equivalent to Set#select!
601
591
  alias filter! select!
602
592
 
603
- # Merges the elements of the given enumerable object to the set and
593
+ # Merges the elements of the given enumerable objects to the set and
604
594
  # returns self.
605
- def merge(enum)
606
- if enum.instance_of?(self.class)
607
- @hash.update(enum.instance_variable_get(:@hash))
608
- else
609
- do_with_enum(enum) { |o| add(o) }
595
+ def merge(*enums, **nil)
596
+ enums.each do |enum|
597
+ if enum.instance_of?(self.class)
598
+ @hash.update(enum.instance_variable_get(:@hash))
599
+ else
600
+ do_with_enum(enum) { |o| add(o) }
601
+ end
610
602
  end
611
603
 
612
604
  self
@@ -854,7 +846,7 @@ module Enumerable
854
846
  # Needs to `require "set"` to use this method.
855
847
  def to_set(klass = Set, *args, &block)
856
848
  klass.new(self, *args, &block)
857
- end
849
+ end unless method_defined?(:to_set)
858
850
  end
859
851
 
860
852
  autoload :SortedSet, "#{__dir__}/set/sorted_set"
data/set.gemspec CHANGED
@@ -1,6 +1,13 @@
1
+ name = File.basename(__FILE__, ".gemspec")
2
+ version = ["lib", Array.new(name.count("-")+1, "..").join("/")].find do |dir|
3
+ break File.foreach(File.join(__dir__, dir, "#{name.tr('-', '/')}.rb")) do |line|
4
+ /^\s*VERSION\s*=\s*"(.*)"/ =~ line and break $1
5
+ end rescue nil
6
+ end
7
+
1
8
  Gem::Specification.new do |spec|
2
- spec.name = "set"
3
- spec.version = "1.0.2"
9
+ spec.name = name
10
+ spec.version = version
4
11
  spec.authors = ["Akinori MUSHA"]
5
12
  spec.email = ["knu@idaemons.org"]
6
13
 
@@ -8,7 +15,7 @@ Gem::Specification.new do |spec|
8
15
  spec.description = %q{Provides a class to deal with collections of unordered, unique values}
9
16
  spec.homepage = "https://github.com/ruby/set"
10
17
  spec.licenses = ["Ruby", "BSD-2-Clause"]
11
- spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
18
+ spec.required_ruby_version = Gem::Requirement.new(">= 3.0.0")
12
19
 
13
20
  spec.metadata["homepage_uri"] = spec.homepage
14
21
  spec.metadata["source_code_uri"] = spec.homepage
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: set
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akinori MUSHA
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-25 00:00:00.000000000 Z
11
+ date: 2023-12-23 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Provides a class to deal with collections of unordered, unique values
14
14
  email:
@@ -17,6 +17,8 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
+ - ".github/CODEOWNERS"
21
+ - ".github/dependabot.yml"
20
22
  - ".github/workflows/test.yml"
21
23
  - ".gitignore"
22
24
  - CHANGELOG.md
@@ -36,8 +38,8 @@ licenses:
36
38
  metadata:
37
39
  homepage_uri: https://github.com/ruby/set
38
40
  source_code_uri: https://github.com/ruby/set
39
- changelog_uri: https://github.com/ruby/set/blob/v1.0.2/CHANGELOG.md
40
- post_install_message:
41
+ changelog_uri: https://github.com/ruby/set/blob/v1.1.0/CHANGELOG.md
42
+ post_install_message:
41
43
  rdoc_options: []
42
44
  require_paths:
43
45
  - lib
@@ -45,15 +47,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
45
47
  requirements:
46
48
  - - ">="
47
49
  - !ruby/object:Gem::Version
48
- version: 2.3.0
50
+ version: 3.0.0
49
51
  required_rubygems_version: !ruby/object:Gem::Requirement
50
52
  requirements:
51
53
  - - ">="
52
54
  - !ruby/object:Gem::Version
53
55
  version: '0'
54
56
  requirements: []
55
- rubygems_version: 3.2.22
56
- signing_key:
57
+ rubygems_version: 3.4.10
58
+ signing_key:
57
59
  specification_version: 4
58
60
  summary: Provides a class to deal with collections of unordered, unique values
59
61
  test_files: []