set 1.0.3 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/CODEOWNERS +1 -0
- data/.github/workflows/test.yml +2 -2
- data/CHANGELOG.md +19 -0
- data/lib/set.rb +29 -37
- data/set.gemspec +10 -3
- metadata +9 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cef560e603f6d6413751c31bb94fddf3838a66af8e71cff73c74760ff479ff6a
|
4
|
+
data.tar.gz: 448e22e93eebe57b26200fc1c8be476d60494193136aabb09a50c68e878e96cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91fa3052d7f25eaf6c0066013a5bd2d0c58961fe330c8923853634bac908ae83323d01b26ec8f85c4ab1ae309a83cc8e30e0918802ebb6f96fc3fcb7b7bdd433
|
7
|
+
data.tar.gz: 07b57081279057d476e1fe7c07587db1de0243cb78d36bc04b5b3ed303643b54320f08e98ed3672e610df84c42f0d503c7fae7eba040d2cf260c84319e7f9745
|
data/.github/CODEOWNERS
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
* @knu
|
data/.github/workflows/test.yml
CHANGED
@@ -7,11 +7,11 @@ jobs:
|
|
7
7
|
name: build (${{ matrix.ruby }} / ${{ matrix.os }})
|
8
8
|
strategy:
|
9
9
|
matrix:
|
10
|
-
ruby: [ 2
|
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@
|
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-
|
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
|
16
|
-
# of unordered values with no duplicates.
|
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
|
@@ -156,7 +152,7 @@
|
|
156
152
|
# If the given object is not an element in the set,
|
157
153
|
# adds it and returns +self+; otherwise, returns +nil+.
|
158
154
|
# - \#merge:
|
159
|
-
#
|
155
|
+
# Merges the elements of each given enumerable object to the set; returns +self+.
|
160
156
|
# - \#replace:
|
161
157
|
# Replaces the contents of the set with the contents
|
162
158
|
# of a given enumerable.
|
@@ -220,6 +216,8 @@
|
|
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
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
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?
|
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?
|
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?
|
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?
|
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?
|
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?
|
474
|
+
any?(set)
|
485
475
|
else
|
486
|
-
set.any?
|
476
|
+
set.any?(self)
|
487
477
|
end
|
488
478
|
when Enumerable
|
489
|
-
set.any?
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
593
|
+
# Merges the elements of the given enumerable objects to the set and
|
604
594
|
# returns self.
|
605
|
-
def merge(
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
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
|
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 =
|
3
|
-
spec.version =
|
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(">=
|
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
|
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:
|
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,7 @@ executables: []
|
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
|
+
- ".github/CODEOWNERS"
|
20
21
|
- ".github/dependabot.yml"
|
21
22
|
- ".github/workflows/test.yml"
|
22
23
|
- ".gitignore"
|
@@ -37,8 +38,8 @@ licenses:
|
|
37
38
|
metadata:
|
38
39
|
homepage_uri: https://github.com/ruby/set
|
39
40
|
source_code_uri: https://github.com/ruby/set
|
40
|
-
changelog_uri: https://github.com/ruby/set/blob/v1.0
|
41
|
-
post_install_message:
|
41
|
+
changelog_uri: https://github.com/ruby/set/blob/v1.1.0/CHANGELOG.md
|
42
|
+
post_install_message:
|
42
43
|
rdoc_options: []
|
43
44
|
require_paths:
|
44
45
|
- lib
|
@@ -46,15 +47,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
46
47
|
requirements:
|
47
48
|
- - ">="
|
48
49
|
- !ruby/object:Gem::Version
|
49
|
-
version:
|
50
|
+
version: 3.0.0
|
50
51
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
52
|
requirements:
|
52
53
|
- - ">="
|
53
54
|
- !ruby/object:Gem::Version
|
54
55
|
version: '0'
|
55
56
|
requirements: []
|
56
|
-
rubygems_version: 3.4.
|
57
|
-
signing_key:
|
57
|
+
rubygems_version: 3.4.10
|
58
|
+
signing_key:
|
58
59
|
specification_version: 4
|
59
60
|
summary: Provides a class to deal with collections of unordered, unique values
|
60
61
|
test_files: []
|