uka.transport
Class WireHashtable

java.lang.Object
  extended byuka.transport.WireHashtable
All Implemented Interfaces:
java.io.Serializable

public class WireHashtable
extends java.lang.Object
implements java.io.Serializable

WireHashtable explained by example: Suppose, 3 objects are already serialized. Each serialized object has an unique offset within the wireHandle2Object (handle2object) table. The next offset to be assigned is nextWireOffset (offset). This offset is used has handle for a newly inserted object 'obj'.

 offset = 3

                                        offset
                                          v
 handle2object  = [ obj0 | obj1 | obj2 ]

                                        offset
                                          v
 handle2object  = [ obj0 | obj1 | obj2 | obj ]
 
An index into the wireHash2Handle (hash2handle) table is generated from the system identity hashcode of obj. This index is used to read the handle for the corresponding object from this table.
 index         = hash(obj) % length(hash2handle)
 
There may be another object already entered to the hashtable with the same hash index. Therefore all objects with the same hash index have to be linked. This happens in the wireNextHandle (nextHandle) table. In the following picture, the object with handle 1 (obj1) has the same hash index as the newly inserted object (obj). Therefore a link from the newly inserted object with handle 4 is created to the formerly inserted object with handle 1. Now the old reference from the 'hash2handle' table at index 'index' to handle 1 can be replaced with the handle of the newly inserted object 'offset' (namely handle 4).
                                              index
                                                v
 hash2handle  = [   |   |   |   |   |   |   |   1    |   |   |   |   ]

                           _          offset
                           |            v
 nexthandle   = [      |  -1  |      |  1  ]
                           ^            |
                           +------------+

                                              index
                                                v
 hash2handle  = [   |   |   |   |   |   |   | offset |   |   |   |   ]
 
When searching for an object with a known hash index, all objects from 'handle2object' with the following handles have to be considered:

 hash2handle[index], 
 nexthandle[hash2handle[index]],
 nexthandle[nexthandle[hash2handle[index]]],
 nexthandle[nexthandle[nexthandle[hash2handle[index]]],

 and so on.

 
The search is finished, either if the searched object is found in handle2object, or nexthandle points to -1 for the current handle. Last but not least, the offset is incremented.
 offset = 4
 

Author:
Bernhard Haumacher
See Also:
Serialized Form

Field Summary
protected  int nextWireOffset
           
protected  EnlargingArray wireHandle2Object
           
private  int[] wireHash2Handle
           
private  int wireHashCapacity
           
private  int wireHashLoadFactor
           
private  int wireHashSizePower
           
private  int[] wireNextHandle
           
 
Constructor Summary
WireHashtable()
           
 
Method Summary
 int assignWireOffset(java.lang.Object obj)
           
 void assignWireOffset(java.lang.Object obj, int id)
           
private  void dump()
           
 int findWireOffset(java.lang.Object obj)
           
 int getNextWireOffset()
           
 java.lang.Object getObject(int id)
           
private  void growWireHash2Handle(int minSize)
           
private  void hashInsert(java.lang.Object obj, int offset)
           
private  void readObject(java.io.ObjectInputStream s)
           
 void reorderWireOffsets(Permutation permutation)
           
 int reset()
           
 void setNextWireOffset(int next)
           
private  void unmarshalPostProcessing()
          This hash table uses the System.identityHashCode(Object) hash function.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

wireHandle2Object

protected EnlargingArray wireHandle2Object

nextWireOffset

protected int nextWireOffset

wireHash2Handle

private transient int[] wireHash2Handle

wireNextHandle

private transient int[] wireNextHandle

wireHashSizePower

private transient int wireHashSizePower

wireHashLoadFactor

private transient int wireHashLoadFactor

wireHashCapacity

private transient int wireHashCapacity
Constructor Detail

WireHashtable

public WireHashtable()
Method Detail

reset

public int reset()

reorderWireOffsets

public void reorderWireOffsets(Permutation permutation)

findWireOffset

public int findWireOffset(java.lang.Object obj)

dump

private void dump()

assignWireOffset

public int assignWireOffset(java.lang.Object obj)

assignWireOffset

public void assignWireOffset(java.lang.Object obj,
                             int id)

getNextWireOffset

public int getNextWireOffset()

getObject

public java.lang.Object getObject(int id)

growWireHash2Handle

private void growWireHash2Handle(int minSize)

hashInsert

private void hashInsert(java.lang.Object obj,
                        int offset)

setNextWireOffset

public void setNextWireOffset(int next)

unmarshalPostProcessing

private void unmarshalPostProcessing()
This hash table uses the System.identityHashCode(Object) hash function. The value of this function depends on the object identity and changes when unmarshaling or cloning an object. Therefore, the hash table has to be rebuilt after unmarshaling or cloning.


readObject

private void readObject(java.io.ObjectInputStream s)
                 throws java.io.IOException,
                        java.lang.ClassNotFoundException
Throws:
java.io.IOException
java.lang.ClassNotFoundException