Re: set using alternative hash function?

2009-10-16 Thread OKB (not okblacke)
Austin Bingham wrote: To put it in code, I want this: s = set(hash_func = lambda obj: hash(obj.name), eq_func = ...) ... x.name = 'foo' y.name = 'foo' s.add(x) s.add(y) # no-op because of uniqueness criteria assert len(s) == 1 The part of this that seems

Re: set using alternative hash function?

2009-10-16 Thread Dave Angel
Austin Bingham wrote: On Thu, Oct 15, 2009 at 7:49 PM, Ethan Furman et...@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

Re: set using alternative hash function?

2009-10-16 Thread Ethan Furman
Austin Bingham wrote: On Thu, Oct 15, 2009 at 7:49 PM, Ethan Furman et...@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

Re: set using alternative hash function?

2009-10-16 Thread Anthony Tolle
On Oct 16, 12:24 pm, Ethan Furman et...@stoneleaf.us wrote: [snip] 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

Re: set using alternative hash function?

2009-10-16 Thread Carl Banks
On Oct 15, 9:31 pm, Austin Bingham austin.bing...@gmail.com wrote: Yes, what you've got there provides the interface of what I want. And no doubt we could concoct countless ways to implement some version of this. However, if set itself accepted an alternate hash function, then I could do it

Re: set using alternative hash function?

2009-10-15 Thread Chris Rebert
On Thu, Oct 15, 2009 at 4:24 AM, Austin Bingham austin.bing...@gmail.com wrote: 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? Say I've got a collection of objects

Re: set using alternative hash function?

2009-10-15 Thread Duncan Booth
Austin Bingham austin.bing...@gmail.com wrote: 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? Say I've got a collection of objects with names. I'd like to create a

Re: set using alternative hash function?

2009-10-15 Thread Austin Bingham
That's definitely a workable solution, but it still rubs me the wrong way. The uniqueness criteria of a set seems, to me, like a property of the set, whereas the python model forces it onto each set element. Another issue I have with the HashWrapper approach is its space requirements. Logically,

Re: set using alternative hash function?

2009-10-15 Thread Austin Bingham
I guess we see things differently. I think it's quite natural to want a set of unique objects where unique is defined as an operation on some subset/conflation/etc. of the attributes of the elements. That's all that the regular set class is, except that it always uses the hash() function to

Re: set using alternative hash function?

2009-10-15 Thread Diez B. Roggisch
Austin Bingham wrote: 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? Say I've got a collection of objects with names. I'd like to create a set of these objects

Re: set using alternative hash function?

2009-10-15 Thread Diez B. Roggisch
Chris Rebert wrote: On Thu, Oct 15, 2009 at 4:24 AM, Austin Bingham austin.bing...@gmail.com wrote: 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? Say I've got a

Re: set using alternative hash function?

2009-10-15 Thread Diez B. Roggisch
Austin Bingham wrote: That's definitely a workable solution, but it still rubs me the wrong way. The uniqueness criteria of a set seems, to me, like a property of the set, whereas the python model forces it onto each set element. This is a POV, but to to me, the set just deals with a very

Re: set using alternative hash function?

2009-10-15 Thread Diez B. Roggisch
Austin Bingham wrote: On Thu, Oct 15, 2009 at 2:23 PM, Diez B. Roggisch de...@nospam.web.de wrote: Austin Bingham wrote: This is a POV, but to to me, the set just deals with a very minimal protocol - hash-value equality. Whatever you feed it, it has to cope with that. It strikes *me* as

Re: set using alternative hash function?

2009-10-15 Thread Austin Bingham
On Thu, Oct 15, 2009 at 3:02 PM, Diez B. Roggisch de...@nospam.web.de wrote: Austin Bingham wrote: You do. Hashes can collide, and then you need equality. Sets are *based* on equality actually, the hash is just one optimization. ... Right, thanks for clearing that up. Not reading closely

Re: set using alternative hash function?

2009-10-15 Thread Diez B. Roggisch
And if there were something that would decide on context which of several implementations to use, you'd have less to worry. As things are, there isn't such thing (I don't even have the slightest idea what could work), you are as well off with defining two functions. But this context decider

Re: set using alternative hash function?

2009-10-15 Thread Mick Krippendorf
Austin Bingham schrieb: I guess we see things differently. I think it's quite natural to want a set of unique objects where unique is defined as an operation on some subset/conflation/etc. of the attributes of the elements. What you seem to imply is that the hash function imposes some kind of

Re: set using alternative hash function?

2009-10-15 Thread Austin Bingham
On Thu, Oct 15, 2009 at 3:43 PM, Diez B. Roggisch de...@nospam.web.de wrote: The context-decider isn't the same thing because it isn't designed yet :) And most probably won't ever be. It's just the abstract idea that hashing/equality change for one object depending on the circumstances they

Re: set using alternative hash function?

2009-10-15 Thread Anthony Tolle
On Oct 15, 7:24 am, Austin Bingham austin.bing...@gmail.com wrote: [snip] I'd like to create a set of these objects where the hashing is done on these names. [snip] Why not use a dict? The key would be the object name. Pretty much the same behavior as a set (via the key), and you can still

Re: set using alternative hash function?

2009-10-15 Thread Austin Bingham
On Thu, Oct 15, 2009 at 3:50 PM, Mick Krippendorf mad.m...@gmx.de wrote: Austin Bingham schrieb: What you seem to imply is that the hash function imposes some kind of uniqueness constraint on the set which uses it. That's just not the case, the uniqueness constraint is always the (in-)equality

Re: set using alternative hash function?

2009-10-15 Thread Austin Bingham
On Thu, Oct 15, 2009 at 4:06 PM, Anthony Tolle anthony.to...@gmail.com wrote: Why not use a dict?  The key would be the object name.  Pretty much the same behavior as a set (via the key), and you can still easily iterate over the objects. To reiterate, dict only gets me part of what I want.

Re: set using alternative hash function?

2009-10-15 Thread Anthony Tolle
On Oct 15, 10:42 am, Austin Bingham austin.bing...@gmail.com wrote: On Thu, Oct 15, 2009 at 4:06 PM, Anthony Tolle To reiterate, dict only gets me part of what I want. Whereas a set with uniqueness defined over 'obj.name' would guarantee no name collisions, dict only sorta helps me keep

Re: set using alternative hash function?

2009-10-15 Thread Chris Rebert
On Thu, Oct 15, 2009 at 5:22 AM, Diez B. Roggisch de...@nospam.web.de wrote: Chris Rebert wrote: On Thu, Oct 15, 2009 at 4:24 AM, Austin Bingham austin.bing...@gmail.com wrote: If I understand things correctly, the set class uses hash() universally to calculate hash values for its elements.

Re: set using alternative hash function?

2009-10-15 Thread Gabriel Genellina
En Thu, 15 Oct 2009 11:42:20 -0300, Austin Bingham austin.bing...@gmail.com escribió: On Thu, Oct 15, 2009 at 4:06 PM, Anthony Tolle anthony.to...@gmail.com wrote: Why not use a dict?  The key would be the object name.  Pretty much the same behavior as a set (via the key), and you can still

Re: set using alternative hash function?

2009-10-15 Thread Austin Bingham
On Thu, Oct 15, 2009 at 5:15 PM, Gabriel Genellina gagsl-...@yahoo.com.ar wrote: En Thu, 15 Oct 2009 11:42:20 -0300, Austin Bingham austin.bing...@gmail.com escribió: I think you didn't understand correctly Anthony Tolle's suggestion: py class Foo: ...   def __init__(self, name): self.name =

Re: set using alternative hash function?

2009-10-15 Thread Rami Chowdhury
On Thu, 15 Oct 2009 09:11:00 -0700, Austin Bingham austin.bing...@gmail.com wrote: On Thu, Oct 15, 2009 at 5:15 PM, Gabriel Genellina gagsl-...@yahoo.com.ar wrote: En Thu, 15 Oct 2009 11:42:20 -0300, Austin Bingham austin.bing...@gmail.com escribió: I think you didn't understand correctly

Re: set using alternative hash function?

2009-10-15 Thread Anthony Tolle
On Oct 15, 12:11 pm, Austin Bingham austin.bing...@gmail.com wrote: To put it in code, I want this:   s = set(hash_func = lambda obj: hash(obj.name), eq_func = ...)   ...   x.name = 'foo'   y.name = 'foo'   s.add(x)   s.add(y) # no-op because of uniqueness criteria   assert len(s) == 1 I

Re: set using alternative hash function?

2009-10-15 Thread Gabriel Genellina
En Thu, 15 Oct 2009 13:24:18 -0300, Rami Chowdhury rami.chowdh...@gmail.com escribió: On Thu, 15 Oct 2009 09:11:00 -0700, Austin Bingham austin.bing...@gmail.com wrote: On Thu, Oct 15, 2009 at 5:15 PM, Gabriel Genellina gagsl-...@yahoo.com.ar wrote: En Thu, 15 Oct 2009 11:42:20 -0300,

Re: set using alternative hash function?

2009-10-15 Thread Ethan Furman
Austin Bingham wrote: Yes, I can construct a dict as you specify, where all of the keys map to values with name attributes equal to the key. My point is that dict doesn't really help me enforce that beyond simply letting me set it up; it doesn't care about the values at all, just the keys. All

Re: set using alternative hash function?

2009-10-15 Thread Anthony Tolle
On Oct 15, 1:49 pm, Ethan Furman et...@stoneleaf.us wrote: I'm still not sure I understand your concern about the values in a set, though.  Sets keep the first object of a given key, dicts keep the last object of a given key; in both cases, all other objects with the same key are lost. So is

Re: set using alternative hash function?

2009-10-15 Thread Austin Bingham
On Thu, Oct 15, 2009 at 7:05 PM, Anthony Tolle anthony.to...@gmail.com wrote: I wrote a quick subclass of set that does something similar, but uses just one function for the object uniqueness: class MySet(set):    def __init__(self, iterable = (), idfunc = lambda x: x):        self.idfunc =

Re: set using alternative hash function?

2009-10-15 Thread Austin Bingham
On Thu, Oct 15, 2009 at 7:49 PM, Ethan Furman et...@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

Re: set using alternative hash function?

2009-10-15 Thread Austin Bingham
On Thu, Oct 15, 2009 at 8:10 PM, Anthony Tolle anthony.to...@gmail.com wrote: I think that without a practical example of what this would be used for, we're all going to be a little lost on this one. So far, we've not seen the original problem, only the author's preferred method for solving