edu.vt.marian.search
Interface WtdObjSetEnumeration

All Known Implementing Classes:
EmptyWtdObjSetEnum, EnumCacheWtdObjSetEnum, MaxUnionSearcherWtdObjSetEnum, ScaledWtdObjSetEnum, SingletonWtdObjSetEnum, VectorCacheWtdObjSetEnum, VectorWtdObjSetEnum

public abstract interface WtdObjSetEnumeration
extends java.util.Enumeration

A WtdObjSetEnumeration is a very light object, many of which can be generated for each WtdObjSet and all of which can execute concurrently in different threads. Provides the java.util.Enumeration functionality and then some.

Synchronization Note: As with all Enumerations in MARIAN, the nextElement() method in classes implementing this interface should be synchronized, as should skip(), sample() and sampleToWt(). This prevents concurrency problems if callers in two different threads are both stepping through the Enumeration. Now, two callers shouldn't really be sharing a single Enumeration, but it does happen, and a lack of synchronization in that circumstance could be terrible. On the other hand, it does no good to synchronize hasMoreElements(), since in the moment between calling hasMoreElements() and nextElement() anything can happen. So for full threadability, one should always use:
   try
   { while(TRUE) ... nextElement() ... }
   catch( NoSuchElementException e ) {}
rather than:
   while( hasMoreElements() )
   { ... nextElement() ... }

See Also:
Enumeration, WtdObjSet

Method Summary
 int approxNumRemaining()
          Return approximate number of elements left.
 int exactNumRemaining()
          Return exact number of elements remaining in the parent set.
 int maxNumRemaining()
          Return maximum number of elements left.
 int sample(int num, WtdObjBag sampleBag)
          Copy a certain number of elements into a bag.
 int sampleToWt(edu.vt.marian.common.Weight minWt, WtdObjBag sampleBag)
          Copy into a bag all the members of this set with weights >= some weight.
 void skip(int k)
          Skip forward a certain number of elements.
 
Methods inherited from interface java.util.Enumeration
hasMoreElements, nextElement
 

Method Detail

skip

public void skip(int k)
Skip forward a certain number of elements.
Parameters:
k - How many elements to skip.
Throws:
java.util.NoSuchElementException -  

sample

public int sample(int num,
                  WtdObjBag sampleBag)
Copy a certain number of elements into a bag.
Parameters:
num - How many elements to copy.
sampleBag - The WtdObjBag to add elements to.
Returns:
OK -- There were Num elements left, and they all were copied well.
anything else -- Problems.
Throws:
java.util.NoSuchElementException -  

sampleToWt

public int sampleToWt(edu.vt.marian.common.Weight minWt,
                      WtdObjBag sampleBag)
Copy into a bag all the members of this set with weights >= some weight.
Parameters:
minWt - The lowest weight to copy.
sampleBag - The WtdObjBag to add elements to.
Returns:
OK -- There were Num elements left, and they all were copied well.
anything else -- Problems.
Throws:
java.util.NoSuchElementException -  

exactNumRemaining

public int exactNumRemaining()
Return exact number of elements remaining in the parent set.
Returns:
The exact number of elements still to be enumerated.

approxNumRemaining

public int approxNumRemaining()
Return approximate number of elements left.
Returns:
The approximate number of elements still to be enumerated.

maxNumRemaining

public int maxNumRemaining()
Return maximum number of elements left.
Returns:
The maximum number of elements still to be enumerated.