Project

General

Profile

Feature #6589

Set#rehash

Added by marcandre (Marc-Andre Lafortune) almost 5 years ago. Updated over 3 years ago.

Status:
Feedback
Priority:
Normal
Target version:
[ruby-core:45642]

Description

There should be a way to rehash a Set.

s = Set.new([[]])
s.first << 1
# s.rehash # Does not exist!
s.include? [1] # => false, want true

See also:

http://stackoverflow.com/questions/10992423/is-this-expected-behaviour-for-a-set-of-arrays-in-ruby
http://stackoverflow.com/questions/10361400/deleting-a-modified-object-from-a-set-in-a-no-op


Related issues

Related to Ruby trunk - Bug #12970: == Equality of recursive sets fails Open

History

#1 [ruby-core:46458] Updated by mame (Yusuke Endoh) almost 5 years ago

  • Status changed from Open to Assigned

#2 [ruby-core:48258] Updated by yhara (Yutaka HARA) over 4 years ago

  • Target version changed from 2.0.0 to next minor

#3 [ruby-core:49241] Updated by marcandre (Marc-Andre Lafortune) over 4 years ago

Comment about this trivial but needed feature would be appreciated.

#4 [ruby-core:50045] Updated by headius (Charles Nutter) over 4 years ago

Is it specified that Set must be hashtable-based forever? There are alternate ways to implement a Set.

#5 [ruby-core:50060] Updated by marcandre (Marc-Andre Lafortune) over 4 years ago

headius (Charles Nutter) wrote:

Is it specified that Set must be hashtable-based forever? There are alternate ways to implement a Set.

Alternate ways of implementing Set with check/insertion in O(1) that would also work if structures change without a rehash functionality?

In any case, the documentation states that "Set uses Hash as storage", but more importantly that "The equality of each couple of elements is determined according to Object#eql? and Object#hash".

#6 [ruby-core:56223] Updated by knu (Akinori MUSHA) almost 4 years ago

Actually, an undocumented "feature" is that Set does not support an element being modified once it is added.

Maybe we should "clarify" that in the document, or add such a method that recalculates identities of elements. I'm yet to decide which, and the name we could give it.

  • rehash (let's be honest)
  • reset (re-set the set)
  • sync
  • ...

#7 [ruby-core:56280] Updated by knu (Akinori MUSHA) over 3 years ago

  • Status changed from Assigned to Feedback

I added some notes to the rdoc in r42265.

#8 Updated by marcandre (Marc-Andre Lafortune) 5 months ago

  • Related to Bug #12970: == Equality of recursive sets fails added

Also available in: Atom PDF