[Glass] Question on Sets

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[Glass] Question on Sets

SebastianHC
Hi!

I just found out that I have some trouble with Sets here.
I use Gemstone/Web 3.1.0.5

If I do
Set new add: MyClass new; add: MyClass new; yourself inspect
then MyClass is twice in the Set,... I expected such behavior for IndentitySet and not Set.
Similar problem with removing MyClass new from this very Set. The MyClass isn't found in the set eventhough it is there.

Set new add: MyClass new; add: MyClass new; yourself; removeAllPresent: #(MyClass new); yourself

Since this seems to work for "basic/primitive" classes I started to search.

In the documentation I could find the following comment:

"If the Bag or Set contains elements
that are themselves complex objects,
determining the equality is complex and
therefore slower than you might have
hoped. GemStone recommends using Identi
tyBag or IdentitySet for anything but
the most simple unordered collections"

So what would then be my best approach for the following task?
I have HTTP interfaces to my server using a csv based data protocol. I parse the CSV with NeoCSV and
Does this mean for a DELETE request that I will need to take the data delivered, select similar objects from my sets, then remove them with "removeAll: myFoundOnes" ?
I was hoping I could just send a removeAllPresent: myDeliveredfromCSVParsedEntities.
This does currently not work since the Set claims that it doesn't include any of the provided enitites,.. eventhough they there and "similar".

If I implement it with the select first then remove it approach,... what will happen when I want to remove/replace a lot of data? Are there any tricks performance-wise?

I do remember that I once read something in the documentation about having to write my own "=" operand in my classes, but I wasn't able to find it againand I am also not 100% sure anymore.

Any help or advide is highly appreciated!
Thanks
Sebastian

_______________________________________________
Glass mailing list
[hidden email]
http://lists.gemtalksystems.com/mailman/listinfo/glass
Reply | Threaded
Open this post in threaded view
|

Re: [Glass] Question on Sets

Richard Sargent
Administrator
SebastianHC wrote
Set new add: MyClass new; add: MyClass new; yourself inspect
then MyClass is twice in the Set,... I expected such behavior for IndentitySet and not Set.
Similar problem with removing MyClass new from this very Set. The MyClass isn't found in the set eventhough it is there.
The most important factor in using Sets is the definition of equality and hash. If you don't define #=, you typically inherit one from Object which tests on identity. And you no doubt know that #hash must answer the same value for objects that compare equal, if you want to be able to reliably use them in hashed collections.
Reply | Threaded
Open this post in threaded view
|

Re: [Glass] Question on Sets

SebastianHC
Hi Richard,

so I remembered right... thank you!

It is like defining the key fields,.. so to speak...?


Sebastian

Am 04.04.2014 08:55, schrieb Richard Sargent:

> SebastianHC wrote
>> Set new add: MyClass new; add: MyClass new; yourself inspect
>> then MyClass is twice in the Set,... I expected such behavior for
>> IndentitySet and not Set.
>> Similar problem with removing MyClass new from this very Set. The MyClass
>> isn't found in the set eventhough it is there.
> The most important factor in using Sets is the definition of equality and
> hash. If you don't define #=, you typically inherit one from Object which
> tests on identity. And you no doubt know that #hash must answer the same
> value for objects that compare equal, if you want to be able to reliably use
> them in hashed collections.
>
>
>
>
> --
> View this message in context: http://forum.world.st/Glass-Question-on-Sets-tp4752784p4752788.html
> Sent from the GLASS mailing list archive at Nabble.com.
> _______________________________________________
> Glass mailing list
> [hidden email]
> http://lists.gemtalksystems.com/mailman/listinfo/glass
>

_______________________________________________
Glass mailing list
[hidden email]
http://lists.gemtalksystems.com/mailman/listinfo/glass
Reply | Threaded
Open this post in threaded view
|

Re: [Glass] Question on Sets

Richard Sargent
Administrator
SebastianHC wrote
It is like defining the key fields,.. so to speak...?
I'll answer that with a cautious "yes". :-)

Your hash and equality should be based on invariant aspects, if possible. If they depend on attributes that can vary, those attributes should not be changed for any such object that is already in a hashed collection - something that is pretty difficult to know.