From: James Coglan Date: 2008-11-19T07:32:15+09:00 Subject: Re: Subclassing Hash to enforce value uniqueness ala key uniqueness. ------=_Part_33585_28055204.1227047746714 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline > > Every time you add a value you iterate over all the other values to check > whether the value is already there. This makes adding an element O(n). > Having > adding to a datastructure be an O(n) operation is usually a bad idea. > Here's > how I'd probably do it (untested): > > # example (elided) This seems like a good idea, I'd have suggested the same. This is exactly what Set in the standard library does to ensure uniqueness, it puts the members as keys in a hash and lets Ruby sort out the hashtable as efficiently as possible. So a pair of mutually inverted hash tables is probably the way to go. ------=_Part_33585_28055204.1227047746714--