org.basex.index.value
Class DiskValues

java.lang.Object
  extended by org.basex.index.value.DiskValues
All Implemented Interfaces:
Index
Direct Known Subclasses:
UpdatableDiskValues

public class DiskValues
extends java.lang.Object
implements Index

This class provides access to attribute values and text contents stored on disk. The data structure is described in the ValueIndexBuilder class.

Author:
BaseX Team 2005-12, BSD License, Christian Gruen

Field Summary
protected  IndexCache cache
          Cached tokens.
protected  IntObjMap<byte[]> ctext
          Cached texts.
protected  Data data
          Data reference.
protected  DataAccess idxl
          ID lists.
protected  DataAccess idxr
          ID references.
protected  java.lang.Object monitor
          Synchronization object.
protected  java.util.concurrent.atomic.AtomicInteger size
          Number of current index entries.
protected  boolean text
          Value type (texts/attributes).
 
Constructor Summary
  DiskValues(Data d, boolean txt)
          Constructor, initializing the index structure.
protected DiskValues(Data d, boolean txt, java.lang.String pref)
          Constructor, initializing the index structure.
 
Method Summary
 void close()
          Closes the index.
 int count(IndexToken it)
          Returns the (approximate/estimated) number of hits for the specified token.
 void delete(TokenObjMap<IntList> m)
          Delete records from the index.
 EntryIterator entries(IndexEntries input)
          Returns all entries that match the specified token.
 void flush()
          Flushes the buffered data.
protected  int get(byte[] key)
          Binary search for key in the idxr.
protected  int get(byte[] key, int first, int last)
          Binary search for key in the idxr.
protected  IndexIterator idRange(NumericRange tok)
          Performs a range query.
 void index(TokenObjMap<IntList> m)
          Add entries to the index.
 byte[] info()
          Returns information on the index structure.
 void init()
          Initializes the index.
 IndexIterator iter(IndexToken it)
          Returns an iterator for the index results.
protected static IndexIterator iter(IntList ids)
          Returns an iterator for the specified id list.
protected  int pre(int id)
          Returns the pre value for the specified id.
 void replace(byte[] o, byte[] n, int id)
          Remove record from the index.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

idxr

protected final DataAccess idxr
ID references.


idxl

protected final DataAccess idxl
ID lists.


text

protected final boolean text
Value type (texts/attributes).


data

protected final Data data
Data reference.


cache

protected final IndexCache cache
Cached tokens.


ctext

protected final IntObjMap<byte[]> ctext
Cached texts. Increases used memory, but speeds up repeated queries.


monitor

protected final java.lang.Object monitor
Synchronization object.


size

protected final java.util.concurrent.atomic.AtomicInteger size
Number of current index entries.

Constructor Detail

DiskValues

public DiskValues(Data d,
                  boolean txt)
           throws java.io.IOException
Constructor, initializing the index structure.

Parameters:
d - data reference
txt - value type (texts/attributes)
Throws:
java.io.IOException - I/O Exception

DiskValues

protected DiskValues(Data d,
                     boolean txt,
                     java.lang.String pref)
              throws java.io.IOException
Constructor, initializing the index structure.

Parameters:
d - data reference
txt - value type (texts/attributes)
pref - file prefix
Throws:
java.io.IOException - I/O Exception
Method Detail

init

public void init()
Description copied from interface: Index
Initializes the index.

Specified by:
init in interface Index

info

public byte[] info()
Description copied from interface: Index
Returns information on the index structure.

Specified by:
info in interface Index
Returns:
info

count

public int count(IndexToken it)
Description copied from interface: Index
Returns the (approximate/estimated) number of hits for the specified token.

Specified by:
count in interface Index
Parameters:
it - token to be found
Returns:
number of hits

iter

public IndexIterator iter(IndexToken it)
Description copied from interface: Index
Returns an iterator for the index results.

Specified by:
iter in interface Index
Parameters:
it - token to be found
Returns:
sorted pre values for the token

entries

public EntryIterator entries(IndexEntries input)
Description copied from interface: Index
Returns all entries that match the specified token.

Specified by:
entries in interface Index
Parameters:
input - index entries
Returns:
entries

idRange

protected final IndexIterator idRange(NumericRange tok)
Performs a range query. All index values must be numeric.

Important: This method is thread-safe.

Parameters:
tok - index term
Returns:
results

iter

protected static IndexIterator iter(IntList ids)
Returns an iterator for the specified id list.

Parameters:
ids - id list
Returns:
iterator

pre

protected int pre(int id)
Returns the pre value for the specified id.

Parameters:
id - id value
Returns:
pre value

get

protected int get(byte[] key)
Binary search for key in the idxr.

Important: This method is thread-safe.

Parameters:
key - token to be found
Returns:
if the key is found: index of the key else: (-(insertion point) - 1)

get

protected int get(byte[] key,
                  int first,
                  int last)
Binary search for key in the idxr.

Important: This method is thread-safe.

Parameters:
key - token to be found
first - begin of the search interval
last - end of the search interval
Returns:
if the key is found: index of the key else: (-(insertion point) - 1)

flush

public void flush()
Flushes the buffered data.


close

public void close()
Description copied from interface: Index
Closes the index.

Specified by:
close in interface Index

index

public void index(TokenObjMap<IntList> m)
Add entries to the index.

Parameters:
m - a set of pairs

delete

public void delete(TokenObjMap<IntList> m)
Delete records from the index.

Parameters:
m - a set of pairs

replace

public void replace(byte[] o,
                    byte[] n,
                    int id)
Remove record from the index.

Parameters:
o - old record key
n - new record key
id - record id