[squeak-dev] ReferenceStream Problem

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

[squeak-dev] ReferenceStream Problem

Zulq Alam-2
When deserializing Dictionary objects, it looks like they are being
rehashed. Where and why is this happening?


dict1 := Dictionary new.
1 to: 1000 do: [:e | dict1 at: e put: e].

rep1 := ReferenceStream streamedRepresentationOf: dict1.
dict2 := ReferenceStream unStream: rep1.
rep2 := ReferenceStream streamedRepresentationOf: dict2.

dict1 = dict2. " true "
rep1 = rep2. " false "

dict1 array size. " 2560 "
dict2 array size. " 1334 "

dict1 rehash.
dict1 array size. " 1334 "


I'm using ReferenceStreams to store object graphs in a relational
database as a BLOB using Glorp. Glorp determines whether to do an
updated by comparing the serialized form of objects with their last
state. This causes spurious UPDATEs.

Any ideas?

Thanks.
Zulq.


Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] ReferenceStream Problem

Eliot Miranda-2


On Wed, May 6, 2009 at 12:49 PM, Zulq Alam <[hidden email]> wrote:
When deserializing Dictionary objects, it looks like they are being rehashed. Where and why is this happening?

I'm sorry I don't know where, but the why is because a deserialized Dictionary (or Set, or any hashed collection) will, if non-empty, contain newly created/deserialized objects whose identity hashes will differ from those of the serialized ones.  Since Object>>#= defaults to #== and Object>>#hash defaults to #identityHash an equality-hashed collection still needs to be rehashed when deserialized since #= hashes can depend on identityHash.


dict1 := Dictionary new.
1 to: 1000 do: [:e | dict1 at: e put: e].

rep1 := ReferenceStream streamedRepresentationOf: dict1.
dict2 := ReferenceStream unStream: rep1.
rep2 := ReferenceStream streamedRepresentationOf: dict2.

dict1 = dict2. " true "
rep1 = rep2. " false "

dict1 array size. " 2560 "
dict2 array size. " 1334 "

dict1 rehash.
dict1 array size. " 1334 "


I'm using ReferenceStreams to store object graphs in a relational database as a BLOB using Glorp. Glorp determines whether to do an updated by comparing the serialized form of objects with their last state. This causes spurious UPDATEs.

Any ideas?

Thanks.
Zulq.