set using alternative hash function?
ethan at stoneleaf.us
Fri Oct 16 18:24:39 CEST 2009
Austin Bingham wrote:
> On Thu, Oct 15, 2009 at 7:49 PM, Ethan Furman <ethan at stoneleaf.us> wrote:
>>Austin Bingham wrote:
>>I'm feeling really dense about now... What am I missing?
> What you're missing is the entire discussion up to this point. I was
> looking for a way to use an alternative uniqueness criteria in a set
> instance without needing to modify my class.
Really? Is that what you wanted? You know, I would never have guessed
>>>>If I understand things correctly, the set class uses hash()
>>>>universally to calculate hash values for its elements. Is
>>>>there a standard way to have set use a different function?
But hey, perhaps my reading comprehension was not at its best yesterday.
Hmmm, actually, I think I did get that. What I missed is why you care
which object stays in your precious little set, as long as you have one?
If it doesn't matter, use a dict and stop wasting our time. If it
does, tell us why and assuage our curiousity.
>>So is that the behavior you're wanting, keeping the first object and
>>discarding all others? Or is there something else I'm still missing?
> Yes and yes. I want "normal" set behavior, but I want the set to use
> user-provided hash and equality tests, i.e. ones that don't
> necessarily call __hash__ and __eq__ on the candidate elements.
As for what you want: No, it's not currently possible. If it's so big
a deal that the various methods presented don't meet with your approval,
break out the C and write your own. Then you could give that back to
the community instead of your snide remarks.
More information about the Python-list