org.egothor.store
Class Terms

java.lang.Object
  extended by org.egothor.store.Terms

public class Terms
extends java.lang.Object

This objects implements the data structure that uses an 1-level index. The elements are stored in A-Z order in the terms file. Their keys are stored in iterms file. That file organizes the keys as follows:

The keys are organized by groups of size N (N is defined by writer object TermsWriter. The group is stored in this format: LastKeyOfGroup, SKIP, SIZE, 1st, 2nd,...SIZE-th keys. It is obvious that SIZE<=N-1. LastKeyOfGroup is SIZE+1-th key. SIZE is lower than N-1 iff this is the last group of keys. SKIP is the number of bytes we must skip after finishing read of SKIP if we want to read the LastKeyOfGroup of following group. Keys are stored with the offset of their data element in the terms file.

This object is implemented for IListMeta objects.

Author:
Leo Galambos

Constructor Summary
protected Terms(java.lang.String location)
          Constructor for the DiscKeyIndexData object.
 
Method Summary
 void close()
          Close all open files.
 void destroy()
          Destroys the two files - terms and iterms in this structure's directory.
static void destroy(java.lang.String location)
           
 IListMetadataRead elementAt(java.lang.String key)
          Return the element with the given key.
 Sequence<? extends IListMetadata> elements(java.lang.String prefix)
          Return an Enumeration of elements containing the given prefix.
protected  void finalize()
          Close this object and attempt garbage collection.
 SequenceWithClose<IListMetadataRead> getReader()
          Open this data structure for sequential read access.
 void setLocation(java.lang.String location)
          Setter for the DiscKeyIndexData object.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Terms

protected Terms(java.lang.String location)
Constructor for the DiscKeyIndexData object. The directory structure is opened in the given directory which must exist.

Parameters:
location - the directory of the data structure
Method Detail

setLocation

public void setLocation(java.lang.String location)
Setter for the DiscKeyIndexData object. The directory structure is opened in the given directory which must exist. If the object is already connected to a location, it is closed first.

Parameters:
location - the directory of the data structure

getReader

public SequenceWithClose<IListMetadataRead> getReader()
Open this data structure for sequential read access.

Returns:
a KeyIndexDataReader

destroy

public void destroy()
Destroys the two files - terms and iterms in this structure's directory.


destroy

public static void destroy(java.lang.String location)

elementAt

public IListMetadataRead elementAt(java.lang.String key)
Return the element with the given key. It works as follows:

It opens iterms file. Until it is end-of-file:
- read the last element; if our key is lower, then read the group and find your key and its offset to data file ( terms ); if the key is equal to the last element, then get its offset to data file; in any other case just skip SKIP bytes.

Parameters:
key - the key to the desired value
Returns:
the value associated with the given key

elements

public Sequence<? extends IListMetadata> elements(java.lang.String prefix)
Return an Enumeration of elements containing the given prefix.

Parameters:
prefix - the prefix to check for
Returns:
an Enumeration

close

public void close()
Close all open files.


finalize

protected void finalize()
                 throws java.lang.Throwable
Close this object and attempt garbage collection.

Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable - garbage collection, who knows?