set 1.0.4 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +8 -1
- data/CHANGELOG.md +13 -0
- data/LICENSE.txt +1 -1
- data/lib/set.rb +31 -36
- data/set.gemspec +1 -1
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c589eb5330bd847b4d8c3dc01648971ccfba64b7c7e44bdf6fd8e982c7f8f1b2
|
4
|
+
data.tar.gz: 2c592861e01df2d0e3eab083c808694e01f9edaa649c593dcde4db29acbbc28b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d9472b2ab8509ec1772d0c935ae0fc8bfa0df5a6ffd263cefc65b39e24a430aab43863d55393b95df61d83a6dea9943f2a50d1dfa6bafc7b0b672d66f3c4a4b
|
7
|
+
data.tar.gz: 11b76695b6ac8d0a362c350c7a6575c04ff72159fa9fcb6a4277fc5a9a7437a986cc4f9dcb0c728f500c6e68e6e5e09ed016cd9dbf0ab629d6e10bcddc4b8b37
|
data/.github/workflows/test.yml
CHANGED
@@ -3,11 +3,18 @@ name: test
|
|
3
3
|
on: [push, pull_request]
|
4
4
|
|
5
5
|
jobs:
|
6
|
+
ruby-versions:
|
7
|
+
uses: ruby/actions/.github/workflows/ruby_versions.yml@master
|
8
|
+
with:
|
9
|
+
engine: cruby
|
10
|
+
min_version: 3.0
|
11
|
+
|
6
12
|
build:
|
13
|
+
needs: ruby-versions
|
7
14
|
name: build (${{ matrix.ruby }} / ${{ matrix.os }})
|
8
15
|
strategy:
|
9
16
|
matrix:
|
10
|
-
ruby:
|
17
|
+
ruby: ${{ fromJson(needs.ruby-versions.outputs.versions) }}
|
11
18
|
os: [ ubuntu-latest, macos-latest ]
|
12
19
|
runs-on: ${{ matrix.os }}
|
13
20
|
steps:
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
# Set Changelog
|
2
2
|
|
3
|
+
# 1.1.1 (2024-11-29)
|
4
|
+
|
5
|
+
* Enhancements
|
6
|
+
* Fix Set#^ to respect subclasses [#38][] ([@kyanagi][])
|
7
|
+
* Speed up Set#flatten [#39][] ([@kyanagi][])
|
8
|
+
|
9
|
+
# 1.1.0 (2023-12-23)
|
10
|
+
|
11
|
+
* Optimize for and require Ruby >=3
|
12
|
+
|
3
13
|
# 1.0.4 (2023-12-08)
|
4
14
|
|
5
15
|
* Enhancements
|
@@ -44,6 +54,8 @@ This is the first release of set as a gem. Here lists the changes since the ver
|
|
44
54
|
[#20]: https://github.com/ruby/set/pull/20
|
45
55
|
[#29]: https://github.com/ruby/set/pull/29
|
46
56
|
[#30]: https://github.com/ruby/set/pull/30
|
57
|
+
[#38]: https://github.com/ruby/set/pull/38
|
58
|
+
[#39]: https://github.com/ruby/set/pull/39
|
47
59
|
[Feature #17838]: https://bugs.ruby-lang.org/issues/17838
|
48
60
|
[Feature #16989]: https://bugs.ruby-lang.org/issues/16989
|
49
61
|
|
@@ -52,4 +64,5 @@ This is the first release of set as a gem. Here lists the changes since the ver
|
|
52
64
|
[@jeremyevans]: https://github.com/jeremyevans
|
53
65
|
[@k-tsj]: https://github.com/k-tsj
|
54
66
|
[@knu]: https://github.com/knu
|
67
|
+
[@kyanagi]: https://github.com/kyanagi
|
55
68
|
[@marcandre]: https://github.com/marcandre
|
data/LICENSE.txt
CHANGED
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-2024 Akinori MUSHA <knu@iDaemons.org>
|
7
7
|
#
|
8
8
|
# Documentation by Akinori MUSHA and Gavin Sinclair.
|
9
9
|
#
|
@@ -216,7 +216,7 @@
|
|
216
216
|
# has been modified while an element in the set.
|
217
217
|
#
|
218
218
|
class Set
|
219
|
-
VERSION = "1.
|
219
|
+
VERSION = "1.1.1"
|
220
220
|
|
221
221
|
include Enumerable
|
222
222
|
|
@@ -286,18 +286,10 @@ class Set
|
|
286
286
|
@hash = orig.instance_variable_get(:@hash).dup
|
287
287
|
end
|
288
288
|
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
@hash = orig.instance_variable_get(:@hash).clone(**options)
|
294
|
-
end
|
295
|
-
else
|
296
|
-
# Clone internal hash.
|
297
|
-
def initialize_clone(orig)
|
298
|
-
super
|
299
|
-
@hash = orig.instance_variable_get(:@hash).clone
|
300
|
-
end
|
289
|
+
# Clone internal hash.
|
290
|
+
def initialize_clone(orig, **options)
|
291
|
+
super
|
292
|
+
@hash = orig.instance_variable_get(:@hash).clone(**options)
|
301
293
|
end
|
302
294
|
|
303
295
|
def freeze # :nodoc:
|
@@ -343,7 +335,7 @@ class Set
|
|
343
335
|
end
|
344
336
|
end
|
345
337
|
|
346
|
-
#
|
338
|
+
# Returns an array containing all elements in the set.
|
347
339
|
#
|
348
340
|
# Set[1, 2].to_a #=> [1, 2]
|
349
341
|
# Set[1, 'c', :s].to_a #=> [1, "c", :s]
|
@@ -361,16 +353,19 @@ class Set
|
|
361
353
|
klass.new(self, *args, &block)
|
362
354
|
end
|
363
355
|
|
364
|
-
def flatten_merge(set, seen =
|
356
|
+
def flatten_merge(set, seen = {}) # :nodoc:
|
365
357
|
set.each { |e|
|
366
358
|
if e.is_a?(Set)
|
367
|
-
|
359
|
+
case seen[e_id = e.object_id]
|
360
|
+
when true
|
368
361
|
raise ArgumentError, "tried to flatten recursive Set"
|
362
|
+
when false
|
363
|
+
next
|
369
364
|
end
|
370
365
|
|
371
|
-
seen
|
366
|
+
seen[e_id] = true
|
372
367
|
flatten_merge(e, seen)
|
373
|
-
seen
|
368
|
+
seen[e_id] = false
|
374
369
|
else
|
375
370
|
add(e)
|
376
371
|
end
|
@@ -389,7 +384,7 @@ class Set
|
|
389
384
|
# Equivalent to Set#flatten, but replaces the receiver with the
|
390
385
|
# result in place. Returns nil if no modifications were made.
|
391
386
|
def flatten!
|
392
|
-
replace(flatten()) if any?
|
387
|
+
replace(flatten()) if any?(Set)
|
393
388
|
end
|
394
389
|
|
395
390
|
# Returns true if the set contains the given object.
|
@@ -409,7 +404,7 @@ class Set
|
|
409
404
|
when set.instance_of?(self.class) && @hash.respond_to?(:>=)
|
410
405
|
@hash >= set.instance_variable_get(:@hash)
|
411
406
|
when set.is_a?(Set)
|
412
|
-
size >= set.size && set.all?
|
407
|
+
size >= set.size && set.all?(self)
|
413
408
|
else
|
414
409
|
raise ArgumentError, "value must be a set"
|
415
410
|
end
|
@@ -422,7 +417,7 @@ class Set
|
|
422
417
|
when set.instance_of?(self.class) && @hash.respond_to?(:>)
|
423
418
|
@hash > set.instance_variable_get(:@hash)
|
424
419
|
when set.is_a?(Set)
|
425
|
-
size > set.size && set.all?
|
420
|
+
size > set.size && set.all?(self)
|
426
421
|
else
|
427
422
|
raise ArgumentError, "value must be a set"
|
428
423
|
end
|
@@ -435,7 +430,7 @@ class Set
|
|
435
430
|
when set.instance_of?(self.class) && @hash.respond_to?(:<=)
|
436
431
|
@hash <= set.instance_variable_get(:@hash)
|
437
432
|
when set.is_a?(Set)
|
438
|
-
size <= set.size && all?
|
433
|
+
size <= set.size && all?(set)
|
439
434
|
else
|
440
435
|
raise ArgumentError, "value must be a set"
|
441
436
|
end
|
@@ -448,7 +443,7 @@ class Set
|
|
448
443
|
when set.instance_of?(self.class) && @hash.respond_to?(:<)
|
449
444
|
@hash < set.instance_variable_get(:@hash)
|
450
445
|
when set.is_a?(Set)
|
451
|
-
size < set.size && all?
|
446
|
+
size < set.size && all?(set)
|
452
447
|
else
|
453
448
|
raise ArgumentError, "value must be a set"
|
454
449
|
end
|
@@ -479,12 +474,12 @@ class Set
|
|
479
474
|
case set
|
480
475
|
when Set
|
481
476
|
if size < set.size
|
482
|
-
any?
|
477
|
+
any?(set)
|
483
478
|
else
|
484
|
-
set.any?
|
479
|
+
set.any?(self)
|
485
480
|
end
|
486
481
|
when Enumerable
|
487
|
-
set.any?
|
482
|
+
set.any?(self)
|
488
483
|
else
|
489
484
|
raise ArgumentError, "value must be enumerable"
|
490
485
|
end
|
@@ -548,22 +543,22 @@ class Set
|
|
548
543
|
# Deletes every element of the set for which block evaluates to
|
549
544
|
# true, and returns self. Returns an enumerator if no block is
|
550
545
|
# given.
|
551
|
-
def delete_if
|
546
|
+
def delete_if(&block)
|
552
547
|
block_given? or return enum_for(__method__) { size }
|
553
|
-
# @hash.delete_if
|
554
|
-
#
|
555
|
-
select
|
548
|
+
# Instead of directly using @hash.delete_if, perform enumeration
|
549
|
+
# using self.each that subclasses may override.
|
550
|
+
select(&block).each { |o| @hash.delete(o) }
|
556
551
|
self
|
557
552
|
end
|
558
553
|
|
559
554
|
# Deletes every element of the set for which block evaluates to
|
560
555
|
# false, and returns self. Returns an enumerator if no block is
|
561
556
|
# given.
|
562
|
-
def keep_if
|
557
|
+
def keep_if(&block)
|
563
558
|
block_given? or return enum_for(__method__) { size }
|
564
|
-
# @hash.keep_if
|
565
|
-
#
|
566
|
-
reject
|
559
|
+
# Instead of directly using @hash.keep_if, perform enumeration
|
560
|
+
# using self.each that subclasses may override.
|
561
|
+
reject(&block).each { |o| @hash.delete(o) }
|
567
562
|
self
|
568
563
|
end
|
569
564
|
|
@@ -667,7 +662,7 @@ class Set
|
|
667
662
|
# Set[1, 2] ^ Set[2, 3] #=> #<Set: {3, 1}>
|
668
663
|
# Set[1, 'b', 'c'] ^ ['b', 'd'] #=> #<Set: {"d", 1, "c"}>
|
669
664
|
def ^(enum)
|
670
|
-
n =
|
665
|
+
n = self.class.new(enum)
|
671
666
|
each { |o| n.add(o) unless n.delete?(o) }
|
672
667
|
n
|
673
668
|
end
|
data/set.gemspec
CHANGED
@@ -15,7 +15,7 @@ Gem::Specification.new do |spec|
|
|
15
15
|
spec.description = %q{Provides a class to deal with collections of unordered, unique values}
|
16
16
|
spec.homepage = "https://github.com/ruby/set"
|
17
17
|
spec.licenses = ["Ruby", "BSD-2-Clause"]
|
18
|
-
spec.required_ruby_version = Gem::Requirement.new(">=
|
18
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 3.0.0")
|
19
19
|
|
20
20
|
spec.metadata["homepage_uri"] = spec.homepage
|
21
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.
|
4
|
+
version: 1.1.1
|
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: 2024-11-29 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:
|
@@ -38,8 +38,8 @@ licenses:
|
|
38
38
|
metadata:
|
39
39
|
homepage_uri: https://github.com/ruby/set
|
40
40
|
source_code_uri: https://github.com/ruby/set
|
41
|
-
changelog_uri: https://github.com/ruby/set/blob/v1.
|
42
|
-
post_install_message:
|
41
|
+
changelog_uri: https://github.com/ruby/set/blob/v1.1.1/CHANGELOG.md
|
42
|
+
post_install_message:
|
43
43
|
rdoc_options: []
|
44
44
|
require_paths:
|
45
45
|
- lib
|
@@ -47,15 +47,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
47
47
|
requirements:
|
48
48
|
- - ">="
|
49
49
|
- !ruby/object:Gem::Version
|
50
|
-
version:
|
50
|
+
version: 3.0.0
|
51
51
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
53
|
- - ">="
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '0'
|
56
56
|
requirements: []
|
57
|
-
rubygems_version: 3.
|
58
|
-
signing_key:
|
57
|
+
rubygems_version: 3.5.23
|
58
|
+
signing_key:
|
59
59
|
specification_version: 4
|
60
60
|
summary: Provides a class to deal with collections of unordered, unique values
|
61
61
|
test_files: []
|