Feature #6589

Set#rehash

Added by Marc-Andre Lafortune almost 2 years ago. Updated 9 months ago.

[ruby-core:45642]
Status:Feedback
Priority:Normal
Assignee:Akinori MUSHA
Category:lib
Target version:next minor

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

History

#1 Updated by Yusuke Endoh almost 2 years ago

  • Status changed from Open to Assigned

#2 Updated by Yutaka HARA over 1 year ago

  • Target version changed from 2.0.0 to next minor

#3 Updated by Marc-Andre Lafortune over 1 year ago

Comment about this trivial but needed feature would be appreciated.

#4 Updated by Charles Nutter over 1 year ago

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

#5 Updated by Marc-Andre Lafortune over 1 year 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 Updated by Akinori MUSHA 9 months 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 Updated by Akinori MUSHA 9 months ago

  • Status changed from Assigned to Feedback

I added some notes to the rdoc in r42265.

Also available in: Atom PDF