summaryrefslogtreecommitdiff
path: root/lib/set.rb
Commit message (Collapse)AuthorAgeFilesLines
* [DOC] remove redundant paragraph at set.rb (#6472)TJ2023-02-151-6/+2
| | | remove redundant paragraph at set.rb
* [ruby/set] Avoid the `block or return` pattern to save Proc allocationsJean Boussier2023-01-111-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* [DOC] Replace the external URIs to docs with rdoc-refNobuyoshi Nakada2022-10-121-2/+2
|
* [ruby/set] Fix a typoKazuhiro NISHIYAMA2022-05-161-1/+1
| | | | https://github.com/ruby/set/commit/71a876ae81
* [ruby/set] Repair format for What's HereBurdetteLamar2022-04-161-41/+41
| | | | https://github.com/ruby/set/commit/292baacb60
* Make Set a builtin feature [Feature #16989]Akinori MUSHA2022-02-181-1/+1
|
* [ruby/set] Make Set#pretty_print IRB::ColorPrinter friendlyKazuki Tsujimoto2021-09-281-5/+6
| | | | https://github.com/ruby/set/commit/f467028cdb
* [ruby/set] Improve What's Here linksBurdetteLamar2021-07-291-2/+2
| | | | https://github.com/ruby/set/commit/76b056c3b9
* [ruby/set] Improve What's Here linksBurdetteLamar2021-07-291-3/+5
| | | | https://github.com/ruby/set/commit/dd787a3988
* [ruby/set] Update documentation for intersect?/disjoint?Jeremy Evans2021-07-291-3/+7
| | | | https://github.com/ruby/set/commit/35b69e9d69
* [ruby/set] Allow the use of any enumerable in intersect?/disjoint?Jeremy Evans2021-07-291-9/+8
| | | | https://github.com/ruby/set/commit/1a73ab9047
* [ruby/set] Allow Set#intersect? and #disjoint? to accept array argumentJeremy Evans2021-07-291-1/+8
| | | | | | Implements [Feature #17838] https://github.com/ruby/set/commit/d9b389bafa
* [ruby/set] Adding section: What's HereBurdette Lamar2021-05-101-1/+1
| | | | https://github.com/ruby/set/commit/257dc452a7
* [ruby/set] Adding section: What's HereBurdette Lamar2021-05-101-1/+2
| | | | https://github.com/ruby/set/commit/8f4c62768d
* [ruby/set] Adding section: What's HereBurdette Lamar2021-05-101-10/+10
| | | | https://github.com/ruby/set/commit/254d927c8c
* [ruby/set] Adding section: What's HereBurdette Lamar2021-05-101-0/+154
| | | | https://github.com/ruby/set/commit/ab81354de1
* Import set 1.0.1Akinori MUSHA2020-12-221-66/+64
| | | | | - Eliminate warnings - Convert rdoc to markdown
* Import set 1.0.0Akinori MUSHA2020-12-221-0/+8
| | | | | | | | - 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
* [ruby/set] Add `Set#<=>`Marc-Andre Lafortune2020-12-041-3/+16
| | | | https://github.com/ruby/set/commit/447974a374
* [ruby/set] Remove SortedSet implementationsAkinori MUSHA2020-12-041-246/+1
| | | | | | | | | | | | | 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
* [ruby/set] Resurrect support for Ruby 2.xAkinori MUSHA2020-12-041-4/+12
| | | | | | In Ruby 2.x, initialize_copy does not take a freeze option. https://github.com/ruby/set/commit/3da6c309df
* Make mutating the result of SortedSet#to_a not affect the setJeremy Evans2020-06-111-1/+1
| | | | Fixes [Bug #15834]
* Support obj.clone(freeze: true) for freezing cloneJeremy Evans2020-03-221-1/+1
| | | | | | | | | | | | | | | | | | 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]
* Call initialize_clone with freeze: false if clone called with freeze: falseJeremy Evans2020-01-031-2/+2
| | | | | | | | | | | | | | | | | | | 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]
* speed up set intersectOleg Zubchenko2019-12-311-1/+9
|
* Deprecate taint/trust and related methods, and make the methods no-opsJeremy Evans2019-11-181-10/+0
| | | | | | 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.
* Fix SortedSet subclasses that override initializeJeremy Evans2019-09-061-1/+2
| | | | | | | | | | | | | 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]
* raise FrozenError instead of RuntimeErrorkazu2019-01-201-1/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66875 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Add a new #filter alias for #selecteregon2018-02-251-0/+3
| | | | | | | | | | | | | | | * 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
* lib/set.rb: [DOC] remove empty commentsstomar2017-11-221-4/+4
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60881 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* set.rb: improve docs for Setstomar2017-11-221-33/+28
| | | | | | | | * 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
* Add examples to Set documentation [ci skip]knu2017-11-171-7/+47
| | | | | | | 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
* lib/set.rb: improve docs for Set#===stomar2017-10-291-6/+11
| | | | | | * 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
* Add `Set#reset`knu2017-10-221-0/+18
| | | | | | | 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
* Avoid use of `self.class.new(self)` in Set#collect!knu2017-10-211-1/+3
| | | | | | | | | 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
* Fix comparison methods of Set to check if `@hash` is actually comparableknu2017-10-211-4/+4
| | | | | | | 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
* Use a mutex to make SortedSet.setup thread-safeknu2017-10-211-90/+92
| | | | | | This should fix [Bug #13735]. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60304 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Remove redundant use of module_evalknu2017-10-211-8/+6
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60303 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Allow a SortedSet to be frozen and still functional [Bug #12091]knu2017-10-211-0/+5
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60298 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Alias Set#=== to #include?knu2017-09-191-0/+17
| | | | | | | | * 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
* Alias Set#to_s to #inspect [ruby-core:81753] [Feature #13676]knu2017-07-141-0/+2
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59332 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Add Set#compare_by_identity and Set#compare_by_identity?knu2016-11-051-2/+20
| | | | | | | * 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
* * lib/set.rb: [DOC] add documentation that ↵ktsj2016-05-041-4/+11
| | | | | | | | 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
* * lib/set.rb (Set#{delete_if,keep_if,collect!,reject!,select!,classify,divide},ktsj2016-05-041-9/+9
| | | | | | | | 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
* * lib/set.rb: Enable frozen_string_literal.knu2015-11-161-1/+3
| | | | | | * 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
* Explain the reason for calling do_with_enum without a block [ci skip]knu2015-11-161-1/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52592 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * lib/set.rb (Hash#flatten!, #add?, #delete?, #collect!, #reject!,knu2015-11-161-23/+8
| | | | | | | #select!, #^, #classify): Micro-optimize some methods for performance and readability. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52591 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * lib/set.rb (#>=, #>, #<=, #<): Make use of Hash#>=, #>, #<, andknu2015-11-161-12/+32
| | | | | | #<= when comparing against an instance of the same kind. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52586 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * lib/set.rb: Make Set#each and SortedSet#each generate a sizedknu2015-06-151-2/+2
| | | | | | | | | enumerator. [GH-931] by kachick (Kenichi Kamiya) * test/test_set.rb: Import tests from Set into SortedSet. [GH-931] by kachick (Kenichi Kamiya) git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50908 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * hash.c: Added docs to explain that #include? and #member? do nothsbt2015-02-171-0/+5
| | | | | | | check member equality * lib/set.rb: ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49616 b2dd03c8-39d4-4d8f-98ff-823fe69b080e