[ruby-core:121072] [Ruby master Feature#16993] Sets: from hash keys using Hash#key_set
From:
"greggzst (Grzegorz Jakubiak) via ruby-core" <ruby-core@...>
Date:
2025-02-15 22:53:11 UTC
List:
ruby-core #121072
Issue #16993 has been updated by greggzst (Grzegorz Jakubiak).
nobu (Nobuyoshi Nakada) wrote in #note-5:
> This kind of extensions should be done in the corresponding library side, set.rb.
Thanks for pointing that out. Here's the PR https://github.com/ruby/set/pull/40
Dan0042 (Daniel DeLorme) wrote in #note-6:
> I like the concept but I'm going to bikeshed the naming: by itself "key_set" is unclear if you don't already know what it does. It sounds like the purpose is to set a key (like instance_variable_set). I'd prefer something a bit more descriptive like "keys_to_set"
Good point I addressed that
----------------------------------------
Feature #16993: Sets: from hash keys using Hash#key_set
https://bugs.ruby-lang.org/issues/16993#change-111989
* Author: marcandre (Marc-Andre Lafortune)
* Status: Open
----------------------------------------
To create a set from hash keys currently implies a temporary array for all keys, rehashing all those keys and rebuilding a hash. Instead, the hash could be copied and its values set to `true`.
```ruby
h = {a: 1}
# Now:
Set.new(h.keys) # => Set[:a]
# After
h.key_set # => Set[:a], efficiently.
```
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/