org.apache.lucene.spelt
Class FreqData

Object
  extended by FreqData

 class FreqData
extends Object

A fast, simple, in-memory data structure for holding frequency data used to produce spelling suggestions.

Author:
Martin Haye

Field Summary
private  IntList counts
          One count per key
private  LongList keys
          List of keys
(package private) static long MAGIC_NUM
          Magic number stored in file when data is written
private static int MAX_UNSORTED
          Upper limit on the number of unsorted entries
private  int sortTop
          Tracks the section of the data that has been sorted.
 
Constructor Summary
FreqData()
           
 
Method Summary
 void add(File f)
          Append sorted counts from an input stream that were saved by save(File).
 void add(long hash, int count)
          Add a count for a given hash code and count
 void add(String word, int count)
          Add a count for a given word
 void add(String word1, String word2, int count)
          Add a count for a given word pair
 int get(long hash)
          Get the count for a given hash code, or zero if not found
 int get(String word)
          Get the count for a given word, or zero if not found
 int get(String word1, String word2)
          Get the count for a given word pair, or zero if not found
 void save(File f)
          Save sorted counts to an input stream.
private  int searchSorted(long hash)
          Search within the sorted keys for the given one.
private  void sort()
          If not already sorted, re-sort the data
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

keys

private LongList keys
List of keys


counts

private IntList counts
One count per key


sortTop

private int sortTop
Tracks the section of the data that has been sorted.


MAX_UNSORTED

private static final int MAX_UNSORTED
Upper limit on the number of unsorted entries

See Also:
Constant Field Values

MAGIC_NUM

static final long MAGIC_NUM
Magic number stored in file when data is written

See Also:
Constant Field Values
Constructor Detail

FreqData

FreqData()
Method Detail

add

public final void add(String word,
                      int count)
Add a count for a given word


add

public final void add(String word1,
                      String word2,
                      int count)
Add a count for a given word pair


add

public void add(long hash,
                int count)
Add a count for a given hash code and count


searchSorted

private int searchSorted(long hash)
Search within the sorted keys for the given one.


get

public final int get(String word)
Get the count for a given word, or zero if not found


get

public final int get(String word1,
                     String word2)
Get the count for a given word pair, or zero if not found


get

public final int get(long hash)
Get the count for a given hash code, or zero if not found


add

public void add(File f)
         throws IOException
Append sorted counts from an input stream that were saved by save(File).

Parameters:
f - File to load from
Throws:
IOException - if anything goes wrong

save

public void save(File f)
          throws IOException
Save sorted counts to an input stream. These can later be loaded by add(File).

Parameters:
f - File to write to (existing contents are replaced)
Throws:
IOException - if anything goes wrong

sort

private void sort()
If not already sorted, re-sort the data