de.pado.dv
Class FrequencyList

java.lang.Object
  extended by java.util.AbstractMap
      extended by java.util.HashMap
          extended by de.pado.dv.FrequencyList
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.Map

public class FrequencyList
extends java.util.HashMap

This class models a hash map whose keys are Strings, and values are Doubles to keep track of frequency counts. The hash table can be kept at constant size by removing the most infrequent entries.

See Also:
Serialized Form

Method Summary
 java.util.List entriesByFrequency()
          Returns a list representation of the entries in the FrequencyList, sorted according to inverse frequency (largest first).
 java.util.List entriesNatural()
          Returns a list representation of the entries in the FrequencyList, sorted according to the keys.
 void inc(java.lang.Object o, java.lang.Double increment)
          Increase the frequency count for o by increment.
 void purge(int maxsize, double ratio)
          Reduces the FrequencyList to size maxsize if its size is larger than maxsize/ratio.
 void resetFrequencies()
          Set all frequencies to zero
 java.lang.String toStringByFrequency()
          Returns a string representation of the FrequencyList, sorted inversely according to the values (greatest frequency first).
 java.lang.String toStringNatural()
          Returns a string representation of the FrequencyList, sorted according to keys.
 
Methods inherited from class java.util.HashMap
clear, clone, containsKey, containsValue, entrySet, get, isEmpty, keySet, put, putAll, remove, size, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Method Detail

inc

public void inc(java.lang.Object o,
                java.lang.Double increment)
Increase the frequency count for o by increment.


purge

public void purge(int maxsize,
                  double ratio)
           throws java.io.IOException
Reduces the FrequencyList to size maxsize if its size is larger than maxsize/ratio. This works by removing infrequent entries until the FrequencyList is small enough. There is no guarantee that the FrequencyList is exactly of size maxsize after purge has been called (can be smaller). If the FrequencyList is smaller than maxsize/ratio, nothing happens.

Throws:
java.io.IOException

entriesByFrequency

public java.util.List entriesByFrequency()
Returns a list representation of the entries in the FrequencyList, sorted according to inverse frequency (largest first). List entries are of type Map.Entry


entriesNatural

public java.util.List entriesNatural()
Returns a list representation of the entries in the FrequencyList, sorted according to the keys. List entries are of type Map.Entry.


toStringByFrequency

public java.lang.String toStringByFrequency()
Returns a string representation of the FrequencyList, sorted inversely according to the values (greatest frequency first).


toStringNatural

public java.lang.String toStringNatural()
Returns a string representation of the FrequencyList, sorted according to keys.


resetFrequencies

public void resetFrequencies()
Set all frequencies to zero