I have a problem with a Bag instance.
When execute this code :
initialize
bag:= Bag new.
bag add: 'Dario'.
bag add: 'Dario'.
bag add:
'Dario'.
bag add: 'Dario'.
voceA := Voce new.
bag add: voceA.
bag add: voceA.
bag add: Voce new.
^bag
Somtime this code answer aBag with two
element:
Dario-> 4
aVoce -> 3.
Somtime this code answer aBag with three
element:
Dario-> 4
aVoce -> 2.
aVoce-> 1.
The Voce class implement the method = . It answer true.
Any
pointers would be greatly
appreciated!
Thanks! Dario _______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc |
You should also implement the #hash method when you implement #=.
#hash should return a small integer that's the same for any two objects that are #=, but not necessarily the other way around (two objects can return the same #hash but not be #=). For a quick #hash implementation I'll often just #bitXor: the #hash values of the instance variables that are compared in #=. If you need a good, robust one to make your Bags, Sets and Dictionaries perform well with thousands and thousands of elements, it'll take more effort and research. - Ash 2009/3/29 Dario Trussardi <[hidden email]>: > I have a problem with a Bag instance. > > When execute this code : > > initialize > > bag:= Bag new. > > bag add: 'Dario'. > bag add: 'Dario'. > bag add: 'Dario'. > bag add: 'Dario'. > > voceA := Voce new. > bag add: voceA. > bag add: voceA. > > bag add: Voce new. > > ^bag > > Somtime this code answer aBag with two element: > > Dario-> 4 > aVoce -> 3. > > Somtime this code answer aBag with three element: > > Dario-> 4 > aVoce -> 2. > aVoce-> 1. > > The Voce class implement the method = . It answer true. > > Any pointers would be greatly appreciated! > > Thanks! > Dario > > > > _______________________________________________ > vwnc mailing list > [hidden email] > http://lists.cs.uiuc.edu/mailman/listinfo/vwnc > > -- http://twitter.com/smashwilson _______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc |
Ash Wilson wrote:
> If you need > a good, robust one to make your Bags, Sets and Dictionaries perform > well with thousands and thousands of elements, it'll take more effort > and research. How can you say that without mentioning Andres' book ;-) Hashing in Smalltalk: Theory and Practice http://www.lulu.com/content/1455536 R - _______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc |
In reply to this post by Ash-15
If Voce>>= answers true, shouldn't the class Voce implement the singleton pattern?...
-----Original Message----- From: [hidden email] [mailto:[hidden email]] On Behalf Of Ash Wilson Sent: Sunday, March 29, 2009 7:56 AM To: Dario Trussardi Cc: [hidden email] Subject: Re: [vwnc] Bag strange behaviour You should also implement the #hash method when you implement #=. #hash should return a small integer that's the same for any two objects that are #=, but not necessarily the other way around (two objects can return the same #hash but not be #=). For a quick #hash implementation I'll often just #bitXor: the #hash values of the instance variables that are compared in #=. If you need a good, robust one to make your Bags, Sets and Dictionaries perform well with thousands and thousands of elements, it'll take more effort and research. - Ash 2009/3/29 Dario Trussardi <[hidden email]>: > I have a problem with a Bag instance. > > When execute this code : > > initialize > > bag:= Bag new. > > bag add: 'Dario'. > bag add: 'Dario'. > bag add: 'Dario'. > bag add: 'Dario'. > > voceA := Voce new. > bag add: voceA. > bag add: voceA. > > bag add: Voce new. > > ^bag > > Somtime this code answer aBag with two element: > > Dario-> 4 > aVoce -> 3. > > Somtime this code answer aBag with three element: > > Dario-> 4 > aVoce -> 2. > aVoce-> 1. > > The Voce class implement the method = . It answer true. > > Any pointers would be greatly appreciated! > > Thanks! > Dario > > > > _______________________________________________ > vwnc mailing list > [hidden email] > http://lists.cs.uiuc.edu/mailman/listinfo/vwnc > > -- http://twitter.com/smashwilson _______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc _______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc |
At 12:35 AM 3/30/2009, Valloud, Andres wrote:
>If Voce>>= answers true, shouldn't the class Voce implement the singleton pattern?... Depends on context. And only necessary if the #hash method answers something other than a constant. ;-) -Jim >-----Original Message----- >From: [hidden email] [mailto:[hidden email]] On Behalf Of Ash Wilson >Sent: Sunday, March 29, 2009 7:56 AM >To: Dario Trussardi >Cc: [hidden email] >Subject: Re: [vwnc] Bag strange behaviour > >You should also implement the #hash method when you implement #=. >#hash should return a small integer that's the same for any two objects that are #=, but not necessarily the other way around (two objects can return the same #hash but not be #=). > >For a quick #hash implementation I'll often just #bitXor: the #hash values of the instance variables that are compared in #=. If you need a good, robust one to make your Bags, Sets and Dictionaries perform well with thousands and thousands of elements, it'll take more effort and research. > >- Ash > >2009/3/29 Dario Trussardi <[hidden email]>: >> I have a problem with a Bag instance. >> >> When execute this code : >> >> initialize >> >> bag:= Bag new. >> >> bag add: 'Dario'. >> bag add: 'Dario'. >> bag add: 'Dario'. >> bag add: 'Dario'. >> >> voceA := Voce new. >> bag add: voceA. >> bag add: voceA. >> >> bag add: Voce new. >> >> ^bag >> >> Somtime this code answer aBag with two element: >> >> Dario-> 4 >> aVoce -> 3. >> >> Somtime this code answer aBag with three element: >> >> Dario-> 4 >> aVoce -> 2. >> aVoce-> 1. >> >> The Voce class implement the method = . It answer true. >> >> Any pointers would be greatly appreciated! >> >> Thanks! >> Dario >> >> >> >> _______________________________________________ >> vwnc mailing list >> [hidden email] >> http://lists.cs.uiuc.edu/mailman/listinfo/vwnc >> >> > > > >-- >http://twitter.com/smashwilson > >_______________________________________________ >vwnc mailing list >[hidden email] >http://lists.cs.uiuc.edu/mailman/listinfo/vwnc > >_______________________________________________ >vwnc mailing list >[hidden email] >http://lists.cs.uiuc.edu/mailman/listinfo/vwnc _______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc |
Do you have good examples where #= is ^true, but the singleton pattern
is not a good idea? -----Original Message----- From: cstb [mailto:[hidden email]] Sent: Monday, March 30, 2009 1:27 PM To: Valloud, Andres Cc: VW NC Subject: Re: [vwnc] Bag strange behaviour At 12:35 AM 3/30/2009, Valloud, Andres wrote: >If Voce>>= answers true, shouldn't the class Voce implement the singleton pattern?... Depends on context. And only necessary if the #hash method answers something other than a constant. ;-) -Jim >-----Original Message----- >From: [hidden email] [mailto:[hidden email]] On >Behalf Of Ash Wilson >Sent: Sunday, March 29, 2009 7:56 AM >To: Dario Trussardi >Cc: [hidden email] >Subject: Re: [vwnc] Bag strange behaviour > >You should also implement the #hash method when you implement #=. >#hash should return a small integer that's the same for any two objects return the same #hash but not be #=). > >For a quick #hash implementation I'll often just #bitXor: the #hash values of the instance variables that are compared in #=. If you need a good, robust one to make your Bags, Sets and Dictionaries perform well with thousands and thousands of elements, it'll take more effort and research. > >- Ash > >2009/3/29 Dario Trussardi <[hidden email]>: >> I have a problem with a Bag instance. >> >> When execute this code : >> >> initialize >> >> bag:= Bag new. >> >> bag add: 'Dario'. >> bag add: 'Dario'. >> bag add: 'Dario'. >> bag add: 'Dario'. >> >> voceA := Voce new. >> bag add: voceA. >> bag add: voceA. >> >> bag add: Voce new. >> >> ^bag >> >> Somtime this code answer aBag with two element: >> >> Dario-> 4 >> aVoce -> 3. >> >> Somtime this code answer aBag with three element: >> >> Dario-> 4 >> aVoce -> 2. >> aVoce-> 1. >> >> The Voce class implement the method = . It answer true. >> >> Any pointers would be greatly appreciated! >> >> Thanks! >> Dario >> >> >> >> _______________________________________________ >> vwnc mailing list >> [hidden email] >> http://lists.cs.uiuc.edu/mailman/listinfo/vwnc >> >> > > > >-- >http://twitter.com/smashwilson > >_______________________________________________ >vwnc mailing list >[hidden email] >http://lists.cs.uiuc.edu/mailman/listinfo/vwnc > >_______________________________________________ >vwnc mailing list >[hidden email] >http://lists.cs.uiuc.edu/mailman/listinfo/vwnc _______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc |
Valloud, Andres wrote:
> Do you have good examples where #= is ^true, but the singleton pattern > is not a good idea? > I believe that it's *always*, singleton pattern or not, illegal to implement #= as ^true. This is because the argument may be any object in the system, and some of those objects surely answer different values for #hash, and therefore cannot all be considered #= to a given receiver, which must answer only one value for its #hash. If you violate the "equal objects must have equal hashes" development constraint, your objects will break hashed collections, which may well be what is happening to the Bag in this thread. Regards, -Martin _______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc |
Free forum by Nabble | Edit this page |