Граф коммитов

134 Коммитов

Автор SHA1 Сообщение Дата
Akinori MUSHA 49cdf063d6 [ruby/set] Bump version to 1.0.4
https://github.com/ruby/set/commit/efc8c8c9f5
2023-12-08 12:37:30 +00:00
Akinori MUSHA ed887cbb4c [ruby/set] Update lib/set.rb
https://github.com/ruby/set/commit/bc59f85f2f
2023-04-25 01:58:12 +00:00
Hiroshi SHIBATA 15796ae1e8 [ruby/set] Expose Set::VERSION
https://github.com/ruby/set/commit/d39b33f463
2023-04-25 01:58:12 +00:00
Akinori MUSHA 5d5ff6e5ed [ruby/set] Set#merge does not take keyword arguments as a Hash
https://github.com/ruby/set/commit/ca1c9532a9
2023-02-24 11:48:08 +00:00
Akinori MUSHA 454ac4cbb2 [ruby/set] Set#merge takes many enumerable objects like Hash#merge! does
https://github.com/ruby/set/commit/becaca994d
2023-02-24 11:48:07 +00:00
TJ fba8f7783b
[DOC] remove redundant paragraph at set.rb (#6472)
remove redundant paragraph at set.rb
2023-02-15 12:46:16 +09:00
Jean Boussier e85ef212de [ruby/set] Avoid the `block or return` pattern to save Proc allocations
Using the block param in a boolean context like this cause it to be
allocated.

Using it with an `if` or `unless` was optimized in 3.2
(https://github.com/ruby/ruby/pull/6286) but using it with `or`
or `and` wasn't.

```ruby
def foo(&block)
  block or return 1
end

puts RubyVM::InstructionSequence.of(method(:foo)).disasm
== disasm: #<ISeq:foo@(irb):11 (11,0)-(13,3)> (catch: false)
local table (size: 1, argc: 0 [opts: 0, rest: -1, post: 0, block: 0, kw: -1@-1, kwrest: -1])
[ 1] block@0<Block>
0000 getblockparam                          block@0, 0                (  12)[LiCa]
0003 dup
0004 branchif                               10
0006 pop
0007 putobject_INT2FIX_1_
0008 leave                                  [Re]
0009 putnil
0010 leave
```

versus

```
def foo(&block)
  return 1 if block
end

puts RubyVM::InstructionSequence.of(method(:foo)).disasm
== disasm: #<ISeq:foo@(irb):15 (15,0)-(17,3)> (catch: false)
local table (size: 1, argc: 0 [opts: 0, rest: -1, post: 0, block: 0, kw: -1@-1, kwrest: -1])
[ 1] block@0<Block>
0000 getblockparamproxy                     block@0, 0                (  16)[LiCa]
0003 branchunless                           7
0005 putobject_INT2FIX_1_
0006 leave                                                            (  17)[Re]
0007 putnil                                                           (  16)
0008 leave
```

https://github.com/ruby/set/commit/e89da977d4
2023-01-11 09:26:08 +00:00
Nobuyoshi Nakada 3539da64fc
[DOC] Replace the external URIs to docs with rdoc-ref 2022-10-12 12:27:40 +09:00
Kazuhiro NISHIYAMA f2dc972940 [ruby/set] Fix a typo
https://github.com/ruby/set/commit/71a876ae81
2022-05-16 23:43:04 +09:00
BurdetteLamar 723debc9a9 [ruby/set] Repair format for What's Here
https://github.com/ruby/set/commit/292baacb60
2022-04-16 15:34:34 +09:00
Akinori MUSHA dd3501bb95 Make Set a builtin feature [Feature #16989] 2022-02-18 11:56:24 +09:00
Kazuki Tsujimoto f360ebb306 [ruby/set] Make Set#pretty_print IRB::ColorPrinter friendly
https://github.com/ruby/set/commit/f467028cdb
2021-09-28 17:37:41 +09:00
BurdetteLamar 1e04571da0 [ruby/set] Improve What's Here links
https://github.com/ruby/set/commit/76b056c3b9
2021-07-29 14:18:52 +09:00
BurdetteLamar 2bd68e32e7 [ruby/set] Improve What's Here links
https://github.com/ruby/set/commit/dd787a3988
2021-07-29 14:18:42 +09:00
Jeremy Evans 52e602edda [ruby/set] Update documentation for intersect?/disjoint?
https://github.com/ruby/set/commit/35b69e9d69
2021-07-29 14:18:25 +09:00
Jeremy Evans cafa7d8975 [ruby/set] Allow the use of any enumerable in intersect?/disjoint?
https://github.com/ruby/set/commit/1a73ab9047
2021-07-29 14:18:18 +09:00
Jeremy Evans 571dafdc7f [ruby/set] Allow Set#intersect? and #disjoint? to accept array argument
Implements [Feature #17838]

https://github.com/ruby/set/commit/d9b389bafa
2021-07-29 14:18:10 +09:00
Burdette Lamar 61e4499545
[ruby/set] Adding section: What's Here
https://github.com/ruby/set/commit/257dc452a7
2021-05-10 16:08:29 +09:00
Burdette Lamar 0a74547942
[ruby/set] Adding section: What's Here
https://github.com/ruby/set/commit/8f4c62768d
2021-05-10 16:08:29 +09:00
Burdette Lamar b8506eb476
[ruby/set] Adding section: What's Here
https://github.com/ruby/set/commit/254d927c8c
2021-05-10 16:08:29 +09:00
Burdette Lamar adc86f7a58
[ruby/set] Adding section: What's Here
https://github.com/ruby/set/commit/ab81354de1
2021-05-10 16:08:29 +09:00
Akinori MUSHA 96b8816793 Import set 1.0.1
- Eliminate warnings
- Convert rdoc to markdown
2020-12-22 21:41:44 +09:00
Akinori MUSHA 3fa4bd8292 Import set 1.0.0
- SortedSet has been removed for dependency and performance reasons.
- Set#join is added as a shorthand for `.to_a.join`.
- Set#<=> is added.

https://github.com/ruby/set/blob/v1.0.0/CHANGELOG.md
2020-12-22 12:20:21 +09:00
Marc-Andre Lafortune 1804c3368c [ruby/set] Add `Set#<=>`
https://github.com/ruby/set/commit/447974a374
2020-12-04 19:24:22 +09:00
Akinori MUSHA a3db08d7b6 [ruby/set] Remove SortedSet implementations
It required RBTree to perform decently and the external dependency was
not suitable for a standard library.  The pure ruby fallback
implementation was originally meant to be an example of how to write a
subclass of Set, and its poor performance was not suitable for use in
production.

I decided it should be distributed as an external library instead of
bundling it with Set.

https://github.com/ruby/set/commit/dfcc8e568b
2020-12-04 19:23:59 +09:00
Akinori MUSHA 46fc8d78a5 [ruby/set] Resurrect support for Ruby 2.x
In Ruby 2.x, initialize_copy does not take a freeze option.

https://github.com/ruby/set/commit/3da6c309df
2020-12-04 19:23:35 +09:00
Jeremy Evans a6cf2f3d22 Make mutating the result of SortedSet#to_a not affect the set
Fixes [Bug #15834]
2020-06-11 14:02:00 -07:00
Jeremy Evans 4f7b435c95 Support obj.clone(freeze: true) for freezing clone
This freezes the clone even if the receiver is not frozen.  It
is only for consistency with freeze: false not freezing the clone
even if the receiver is frozen.

Because Object#clone is now partially implemented in Ruby and
not fully implemented in C, freeze: nil must be supported to
provide the default behavior of only freezing the clone if the
receiver is frozen.

This requires modifying delegate and set, to set freeze: nil
instead of freeze: true as the keyword parameter for
initialize_clone.  Those are the two libraries in stdlib that
override initialize_clone.

Implements [Feature #16175]
2020-03-22 09:30:07 -07:00
Jeremy Evans 04eb7c7e46 Call initialize_clone with freeze: false if clone called with freeze: false
This makes it possible to initialize_clone to correctly not freeze
internal state if the freeze: false keyword is passed to clone.

If clone is called with freeze: true or no keyword, do not pass
a second argument to initialize_clone to keep backwards
compatibility.

This makes it so that external libraries that override
initialize_clone but do not support the freeze keyword will fail
with ArgumentError if passing freeze: false to clone.  I think that
is better than the current behavior, which succeeds but results in
an unfrozen object with frozen internals.

Fix related issues in set and delegate in stdlib.

Fixes [Bug #14266]
2020-01-03 20:13:09 -08:00
Oleg Zubchenko 4ce28b58cb speed up set intersect 2019-12-31 20:52:41 +09:00
Jeremy Evans ffd0820ab3 Deprecate taint/trust and related methods, and make the methods no-ops
This removes the related tests, and puts the related specs behind
version guards.  This affects all code in lib, including some
libraries that may want to support older versions of Ruby.
2019-11-18 01:00:25 +02:00
Jeremy Evans 258843106f Fix SortedSet subclasses that override initialize
The first time SortedSet#initialize is called, it overwrites
itself, then recalls #initialize, which results in calling the
subclass's initialize, not the current initialize.

Just inline the default initialize behavior to avoid this issue.

No test for this as it can only be triggered the very first time
that SortedSet#initialize is called.

Fixes [Bug #15830]
2019-09-06 14:20:22 -07:00
kazu afd68cd871 raise FrozenError instead of RuntimeError
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66875 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-20 04:44:25 +00:00
eregon b1a8c64483 Add a new #filter alias for #select
* In Enumerable, Enumerator::Lazy, Array, Hash and Set
  [Feature #13784] [ruby-core:82285]
* Share specs for the various #select#select! methods and
  reuse them for #filter/#filter!.
* Add corresponding filter tests for select tests.
* Update NEWS.

[Fix GH-1824]

From: Alexander Patrick <adp90@case.edu>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62575 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-25 13:52:07 +00:00
stomar 8692d74b09 lib/set.rb: [DOC] remove empty comments
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60881 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-22 21:13:51 +00:00
stomar 62191f1cc5 set.rb: improve docs for Set
* lib/set.rb: [DOC] add examples for Set#replace,
  add examples for creating a set from a hash with duplicates,
  simplify and fix style of some other examples, fix typos.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60879 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-22 20:58:24 +00:00
knu 8d7d8d0c7f Add examples to Set documentation [ci skip]
GitHub PR:    https://github.com/ruby/ruby/pull/1752 [Fix GH-1752]
Submitted by: @Ana06 <anamma06@gmail.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60824 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-17 09:48:47 +00:00
stomar cd63bec1ed lib/set.rb: improve docs for Set#===
* lib/set.rb: [DOC] improve description and examples for Set#===.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60573 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-29 20:59:33 +00:00
knu 8c90432af7 Add `Set#reset`
This method resets the internal state of a set after modification to
existing elements, reindexing and deduplicating them. [Feature #6589]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60360 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-22 12:25:34 +00:00
knu 0fcac8f1a3 Avoid use of `self.class.new(self)` in Set#collect!
That prevents infinite recursion when a subclass of Set uses
`collect!` in its constructor.

This should fix [Bug #12437].

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60317 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-21 17:03:40 +00:00
knu c1c527c290 Fix comparison methods of Set to check if `@hash` is actually comparable
This should fix comparison of rbtree backed SortedSet instances.
[Bug #12072]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60312 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-21 16:28:52 +00:00
knu 8daa6985dc Use a mutex to make SortedSet.setup thread-safe
This should fix [Bug #13735].

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60304 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-21 15:57:32 +00:00
knu 76e3825376 Remove redundant use of module_eval
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60303 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-21 15:57:26 +00:00
knu 3090169c9b Allow a SortedSet to be frozen and still functional [Bug #12091]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60298 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-21 15:38:38 +00:00
knu 2aee703e7a Alias Set#=== to #include?
* set.rb (Set#===): Added via [Feature #13801] by davidarnold.

Closes #1673.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59966 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-19 08:45:12 +00:00
knu d893c123f6 Alias Set#to_s to #inspect [ruby-core:81753] [Feature #13676]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59332 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-07-14 08:46:13 +00:00
knu 76977611dd Add Set#compare_by_identity and Set#compare_by_identity?
* lib/set.rb (Set#compare_by_identity, Set#compare_by_identity?):
  New methods. [Feature #12210]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56589 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-05 09:23:14 +00:00
ktsj 60287eab74 * lib/set.rb: [DOC] add documentation that Set#{delete_if,keep_if,collect!,reject!,select!,
classify,divide} without block returns an enumerator.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54904 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-04 09:07:01 +00:00
ktsj 80ccb8e86f * lib/set.rb (Set#{delete_if,keep_if,collect!,reject!,select!,classify,divide},
SortedSet#{delete_if,keep_if}): Return sized enumerators.

* test/test_set.rb: add test for above.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54903 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-04 09:06:59 +00:00
knu 5cf4310616 * lib/set.rb: Enable frozen_string_literal.
* lib/set.rb: Move << out of the begin block that ensures pop.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52593 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-16 07:41:30 +00:00