Rehashing of collections
Some types of Collections, such as instances of Dictionary, Set, and their respective subclasses, use a hashing mechanism so that their elements can be accessed efficiently. Objects loaded into a different image or into the same image from which they were unloaded will retain their hash values. Thus, hashed collections containing these objects need not be rehashed when they are loaded. However, if an object is mutated or replaced or its hashing implementation has changed, then the hashed collections containing these objects must be rehashed to ensure their correct behavior. The ObjectLoader assumes that this rehashing process is part of your application because not all applications require these objects to be rehashed each time they are loaded. The next example shows how you can rehash all instances of Set each time an object is loaded.
Example: Rehashing loaded collections
|dumper loader aReadWriteStream rehashedInstances someObject |
someObject := Set with: 1 with: $a with: 2@3.
aReadWriteStream := ReadWriteStream on: ByteArray new.
dumper:= ObjectDumper new.
dumper unload: someObject
intoStream: aReadWriteStream.
dumper hasErrorOccurred ifTrue: [
self error: dumper currentErrorString].
loader := ObjectLoader new.
loader extractInstancesOfClasses:
(Array with: Set).
someObject := loader loadFromStream: aReadWriteStream reset.
loader hasErrorOccurred
ifTrue: [^self error: loader currentErrorString].
rehashedInstances := loader requestedNewlyLoadedInstances.
rehashedInstances do: [:arrayOfInstances |
arrayOfInstances do: :instance | instance rehash]].
someObject inspect.
Last modified date: 01/29/2015