set 1.0.2 → 1.0.4

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: a0553df841f04a61495ba77ce0545d0cf8fe2317a8d4113235bc0ffed4a798f9
4
+ data.tar.gz: a0f42b54d9f2d61932e9b781a8adc33e7fa28eef1e0fe646d51e4cb8a10aac9f
5
5
  SHA512:
6
- metadata.gz: 831b03fe1e1ec4c74188fa91f224411d645aab6cd64d99cb499d1e62a4c0f2c3f660bfc6709c4ace1fdec336b5aae3b32691f70262bc9023cbd427a6a1934b8b
7
- data.tar.gz: 28da11f61439186d2dc7cc091101884fbd1346489720505bcd1dc507c9933893b477696d04c0a832ac26a103cdad9f634b328c3280504fe4ecf7e44e35a75c52
6
+ metadata.gz: 96305ae873bfaf18381f91252201245ef4322ada12644358f0d8d310c54722dac39d6c79b26a270322931d9d4848955542acc3912ec57c75b57bca38994806c3
7
+ data.tar.gz: 77adbb45986b8203e9e11da2e0eea741b36903a2017c4d5d1898b9700b82ec19e1bbff27883e3c485e991cdc67b3f0bde9582605c0a84ed1fc9322409ddad284
@@ -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", 2.7, 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,16 @@
1
1
  # Set Changelog
2
2
 
3
+ # 1.0.4 (2023-12-08)
4
+
5
+ * Enhancements
6
+ * Avoid the `block or return` pattern to save Proc allocations [#29][] ([@casperisfine][])
7
+ * Set#merge takes many enumerable objects [#30][]
8
+
9
+ # 1.0.3 (2022-09-06)
10
+
11
+ * Enhancements
12
+ * Make Set a builtin feature \[[Feature #16989][]]
13
+
3
14
  # 1.0.2 (2021-10-25)
4
15
 
5
16
  * Enhancements
@@ -31,9 +42,13 @@ This is the first release of set as a gem. Here lists the changes since the ver
31
42
  [#17]: https://github.com/ruby/set/pull/17
32
43
  [#18]: https://github.com/ruby/set/pull/18
33
44
  [#20]: https://github.com/ruby/set/pull/20
45
+ [#29]: https://github.com/ruby/set/pull/29
46
+ [#30]: https://github.com/ruby/set/pull/30
34
47
  [Feature #17838]: https://bugs.ruby-lang.org/issues/17838
48
+ [Feature #16989]: https://bugs.ruby-lang.org/issues/16989
35
49
 
36
50
  [@BurdetteLamar]: https://github.com/BurdetteLamar
51
+ [@casperisfine]: https://github.com/casperisfine
37
52
  [@jeremyevans]: https://github.com/jeremyevans
38
53
  [@k-tsj]: https://github.com/k-tsj
39
54
  [@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.0.4"
220
+
223
221
  include Enumerable
224
222
 
225
223
  # Creates a new set containing the given objects.
@@ -507,7 +505,7 @@ class Set
507
505
  # the element as parameter. Returns an enumerator if no block is
508
506
  # given.
509
507
  def each(&block)
510
- block or return enum_for(__method__) { size }
508
+ block_given? or return enum_for(__method__) { size }
511
509
  @hash.each_key(&block)
512
510
  self
513
511
  end
@@ -582,7 +580,7 @@ class Set
582
580
  # Equivalent to Set#delete_if, but returns nil if no changes were
583
581
  # made. Returns an enumerator if no block is given.
584
582
  def reject!(&block)
585
- block or return enum_for(__method__) { size }
583
+ block_given? or return enum_for(__method__) { size }
586
584
  n = size
587
585
  delete_if(&block)
588
586
  self if size != n
@@ -591,7 +589,7 @@ class Set
591
589
  # Equivalent to Set#keep_if, but returns nil if no changes were
592
590
  # made. Returns an enumerator if no block is given.
593
591
  def select!(&block)
594
- block or return enum_for(__method__) { size }
592
+ block_given? or return enum_for(__method__) { size }
595
593
  n = size
596
594
  keep_if(&block)
597
595
  self if size != n
@@ -600,13 +598,15 @@ class Set
600
598
  # Equivalent to Set#select!
601
599
  alias filter! select!
602
600
 
603
- # Merges the elements of the given enumerable object to the set and
601
+ # Merges the elements of the given enumerable objects to the set and
604
602
  # 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) }
603
+ def merge(*enums, **nil)
604
+ enums.each do |enum|
605
+ if enum.instance_of?(self.class)
606
+ @hash.update(enum.instance_variable_get(:@hash))
607
+ else
608
+ do_with_enum(enum) { |o| add(o) }
609
+ end
610
610
  end
611
611
 
612
612
  self
@@ -854,7 +854,7 @@ module Enumerable
854
854
  # Needs to `require "set"` to use this method.
855
855
  def to_set(klass = Set, *args, &block)
856
856
  klass.new(self, *args, &block)
857
- end
857
+ end unless method_defined?(:to_set)
858
858
  end
859
859
 
860
860
  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(">= 2.7.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.0.4
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-08 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.0.4/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: 2.7.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: []