edu.vt.marian.search
Class SetImageWtdObjTable

java.lang.Object
  |
  +--java.util.Dictionary
        |
        +--java.util.Hashtable
              |
              +--edu.vt.marian.search.FullIDTable
                    |
                    +--edu.vt.marian.search.WtdObjTable
                          |
                          +--edu.vt.marian.search.SetImageWtdObjTable

public class SetImageWtdObjTable
extends WtdObjTable

Provides hash table functionality for (doubly-linked) weighted objects keyed on FullIDs, and "threaded" into multiple linked lists. Specifically, the Table is to be used to maintain "images" of a collection of weighted object sets. Since each set is inserted into the table in non-increasing weight order, the images are also in that order. Objects may be removed from each image, rejoining the list around the removed element, the order being maintained.

When this Table is used in a Searcher, each set image is composed of only those objects that occur in only one component set. Objects that occur in more than one set are excised from the set image and added to another list of "multiply hit" elements. Note that the weighted object in question does not leave the table, and does not move within the hash order. The only change to the object (other than accumulating weight) is that its links to next and previous elements are switched from elements in a set image to elements in the multiHit list.

This class is essentially a wrapper around WtdObjTable to impose the set image semantics.

This structure implicitly relies upon the hashCode method to be defined in the object that is going to be used as a key object.

NOTE: Since this Table maintains many separate Enumerations (one for each set image pkus one for multiHit) it cannot be itself an Enumeration.

See Also:
WtdObjTable, WtdObjSingleLink, WtdObj, Hashtable, Debug, Serialized Form

Fields inherited from class edu.vt.marian.search.WtdObjTable
enum
 
Fields inherited from class edu.vt.marian.search.FullIDTable
BAD_PARAMS, debug, NULL_STREAM, OK
 
Constructor Summary
SetImageWtdObjTable(edu.vt.marian.common.Debug debug)
          Create an empty hash table for (singly-linked) weighted objects
SetImageWtdObjTable(int initialCapacity, edu.vt.marian.common.Debug debug)
          Create an empty hash table for (singly-linked) weighted objects specifying initial capacity, but with default load factor.
SetImageWtdObjTable(int initialCapacity, float loadFactor, edu.vt.marian.common.Debug debug)
          Create an empty hash table for (singly-linked) weighted objects specifying initial capacity and load factor.
 
Method Summary
 void clear()
          Clear hash table.
 WtdObjSetEnumeration imageElements(int image)
          Return a WtdObjSetEnumeration for the weighted objects in some set image.
 java.lang.Object insert(edu.vt.marian.common.WtdObj wtdObj)
          Add a weighted object to the table in the set image last selected.
 java.util.Enumeration multiHitElements()
          Return an Enumeration for the weighted objects in the multiHit list.
 int newImage()
          Add a new set image.
 int setImage(int image)
          Change to a previously defined set image.
 
Methods inherited from class edu.vt.marian.search.WtdObjTable
elements, elements, getNext, hasMoreElements, nextElement
 
Methods inherited from class edu.vt.marian.search.FullIDTable
toStream, toString
 
Methods inherited from class java.util.Hashtable
clone, contains, containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keys, keySet, put, putAll, rehash, remove, size, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SetImageWtdObjTable

public SetImageWtdObjTable(edu.vt.marian.common.Debug debug)
Create an empty hash table for (singly-linked) weighted objects

SetImageWtdObjTable

public SetImageWtdObjTable(int initialCapacity,
                           float loadFactor,
                           edu.vt.marian.common.Debug debug)
Create an empty hash table for (singly-linked) weighted objects specifying initial capacity and load factor.
Parameters:
initialCapacity - initial size of hash table
loadFactor - occupancy threshold before growth needed
debug - debugging object

SetImageWtdObjTable

public SetImageWtdObjTable(int initialCapacity,
                           edu.vt.marian.common.Debug debug)
Create an empty hash table for (singly-linked) weighted objects specifying initial capacity, but with default load factor.
Parameters:
initialCapacity - initial size of hash table
debug - debugging object
Method Detail

newImage

public int newImage()
Add a new set image.
Returns:
An integer that will serve as identifier for this image in future calls to selectImage() and imageElements(), or a negative integer on failure [[ if failure is possible. Paul: is it? ]]

setImage

public int setImage(int image)
Change to a previously defined set image.
Parameters:
image - An image ID previously returned by newImage().
Returns:
OK, or some error code on failure. [[ if failure not possible, change method to void ]]

insert

public java.lang.Object insert(edu.vt.marian.common.WtdObj wtdObj)
Add a weighted object to the table in the set image last selected. This method both adds the weighted object into the table and connects it to the end of the last list defined by a newImage() or selected by a selectImage().

OK, PAUL, DESIGN QESTION TIME: Is it better for the Table to maintain multiHit and do both the weight computations and the moving between lists as part of insert(), or should the searcher be responsible for testing isInTable(), snipping the object out of the set image, adding in the new wieght and attaching it to multiHit? My best thinking at the moment is that the Table should maintain multiHit and do the moving, that the WtdObjDoubleLink should handle Weight accumulation, and that the Searcher does nothing but call insert() as many times as it needs. But I'm not completely convinced yet.

Parameters:
wtdObj - weighted object to be inserted
Returns:
null if the weighted object was not already present, otherwise return the Object that was already there.

imageElements

public WtdObjSetEnumeration imageElements(int image)
Return a WtdObjSetEnumeration for the weighted objects in some set image.
Parameters:
image - An image ID previously returned by newImage().
Returns:
A WtdObjSetEnumeration containing weighted object elements in the image selected, or null if the parameter is bad.
See Also:
WtdObjSetEnumeration

multiHitElements

public java.util.Enumeration multiHitElements()
Return an Enumeration for the weighted objects in the multiHit list.
Returns:
Enumeration containing weighted object elements in the list.

NOTE: Unlike the set images, multiHit is not in Weight order, so the ordering of elements in the Enumeration returned is arbitrary.

See Also:
WtdObjTable.nextElement(), WtdObjTable.hasMoreElements()

clear

public void clear()
Clear hash table. This basically just calls the superclass clear() method, but also resets local list variables to null to reflect initial table status.
Overrides:
clear in class java.util.Hashtable
See Also:
Hashtable