Somthing weird in Set

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

Somthing weird in Set

Hilaire Fernandes-4
How can the following happen ?

theSet includes: theOnject -> false
theSet asArray includes: theObject -> true

previous sent messages to theSet were add: remove:ifAbsent:


The Set>>ScanFor: looks strange.

Hilaire

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Somthing weird in Set

Nicolas Cellier-3
It can happen most probably due to problems of hash code.
Two objects that are equal SHOULD have same hash code.
- either YourObject does define #= but does not define #hash
- or you add theObject to theSet, then modify theObject, which has side
effect of modifying its hash code, and then theObject cannot be found in
theSet (in which case you have a cure: theSet rehash)

scanFor: seems to do the right thing: find a slot corresponding to
theObject hash, and look further if this slot is already occupied by
anotherObject.
If storage is sparse enough and hash code are well distributed, this
should lead to an efficient access cost near O(1), while Array includes:
use a linear search O(n).

Nicolas


Hilaire Fernandes a écrit :

> How can the following happen ?
>
> theSet includes: theOnject -> false
> theSet asArray includes: theObject -> true
>
> previous sent messages to theSet were add: remove:ifAbsent:
>
>
> The Set>>ScanFor: looks strange.
>
> Hilaire

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Somthing weird in Set

Hilaire Fernandes-4
nicolas cellier a écrit :
> It can happen most probably due to problems of hash code.
> Two objects that are equal SHOULD have same hash code.
> - either YourObject does define #= but does not define #hash
> - or you add theObject to theSet, then modify theObject, which has side
> effect of modifying its hash code, and then theObject cannot be found in
> theSet (in which case you have a cure: theSet rehash)

Oh, yes it is exactly what it is happening, for odd reason I update the
hash value of the inserted object

Thanks

Hilaire

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners