Project

General

Profile

Bug #16690

[BUG] Set of sets: containing set no longer believes member set is a member after mutating its member set

Added by keithyjohnson (Keith Johnson) 3 months ago. Updated 2 months ago.

Status:
Rejected
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:97453]

Description

Please correct me if I'm wrong but I expected that when mutating a member set of a containing set, that that mutated member set, would still be considered a member of the containing set. But after merging another set into the member set, the containing set no longer believes it to be a member. I was surprised by this, but if that is expected behavior, please let me know! Also, please let me know if you have any more questions.

[1] pry(#<Clustering>)> clusters.class
=> Set
[2] pry(#<Clustering>)> smaller_cluster.class
=> Set
[3] pry(#<Clustering>)> larger_cluster.class
=> Set
[4] pry(#<Clustering>)> x = larger_cluster.object_id
=> 70237123254460
[5] pry(#<Clustering>)> clusters.member?(larger_cluster)
=> true
[6] pry(#<Clustering>)> larger_cluster.merge(smaller_cluster)
=> #<Set: {387, 92}>
[7] pry(#<Clustering>)> larger_cluster.object_id == x
=> true
[8] pry(#<Clustering>)> clusters.member?(larger_cluster)
=> false
[9] pry(#<Clustering>)> clusters.map(&:object_id).include?(larger_cluster.object_id)
=> true
[10] pry(#<Clustering>)> RUBY_VERSION
=> "2.3.0"

Updated by byroot (Jean Boussier) 3 months ago

That's explained in the documentation of the class: https://ruby-doc.org/stdlib-2.7.0/libdoc/set/rdoc/Set.html

Set uses Hash as storage, so you must note the following points:

Set assumes that the identity of each element does not change while it is stored. Modifying an element of a set will render the set to an unreliable state.

#2

Updated by jeremyevans0 (Jeremy Evans) 2 months ago

  • Status changed from Open to Rejected

Also available in: Atom PDF