Project

General

Profile

Actions

Feature #6589

closed

Set#rehash

Added by marcandre (Marc-Andre Lafortune) over 12 years ago. Updated about 7 years ago.

Status:
Closed
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 1 (0 open1 closed)

Related to Ruby master - Bug #12970: == Equality of recursive sets failsClosedActions

Updated by mame (Yusuke Endoh) over 12 years ago

  • Status changed from Open to Assigned

Updated by yhara (Yutaka HARA) about 12 years ago

  • Target version changed from 2.0.0 to 2.6

Updated by marcandre (Marc-Andre Lafortune) about 12 years ago

Comment about this trivial but needed feature would be appreciated.

Updated by headius (Charles Nutter) about 12 years ago

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

Updated by marcandre (Marc-Andre Lafortune) about 12 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".

Updated by knu (Akinori MUSHA) over 11 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
  • ...

Updated by knu (Akinori MUSHA) over 11 years ago

  • Status changed from Assigned to Feedback

I added some notes to the rdoc in r42265.

Actions #8

Updated by marcandre (Marc-Andre Lafortune) about 8 years ago

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

Updated by knu (Akinori MUSHA) about 7 years ago

  • Status changed from Feedback to Closed

Applied in changeset trunk|r60360.


Add Set#reset

This method resets the internal state of a set after modification to
existing elements, reindexing and deduplicating them. [Feature #6589]

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0