Overview | Package | Class | Use | Tree | Help
| HEADER
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## ru.biosoft.access
Class BTreeIndex

    java.lang.Object
      |
      +--java.util.AbstractMap
            |
            +--ru.biosoft.access.BTreeIndex

Direct Known Subclasses:
  BTreeRangeIndex

public class BTreeIndex
extends AbstractMap
implements Index

Maps keys to entries. A index cannot contain duplicate keys; each key can map to at most one entry.

Key and entries stored in file as Balanced Tree.

Keys are strings and entryes are Index.IndexEntry.

Since: 1.2
See Also: Index.IndexEntry
todo Comment, Optimize for speed, Decrease size of index file when indexes removed., HIGH way for specify location for index (or create in temporary) - if dataFile on CD., Describe perfomance.

Inner Class Summary
`public static class` | BTreeIndex.IntKey
`public static class` | BTreeIndex.NodeKey

Field Summary
`final static int` | `DEFAULT_BLOCK_SIZE` Default file block size.
`final static int` | `ROOT_BLOCK_OFFSET` Root block offset

Constructor Summary
`BTreeIndex(File dataFile, String indexName, String indexPath, int blockSize)` Construct index based on specified file.
`BTreeIndex(File dataFile, String indexName, String indexPath)` Create index with DEFAULT_BLOCK_SIZE.

Method Summary
`void` | `clear()` Removes all keys and entries from this index.
`void` | `close()` Close this index and releases resources (index file).
`boolean` | `containsKey(Object key)` Returns `true` if this index contains entry for the specified key.
`Object` | `createNode(byte[] buffer, int pos, String key, IndexEntry value)`
`Object` | `createNode(byte[] buffer, int pos)`
`Set` | `entrySet()` Returns a set view of the mappings contained in this index.
`Object` | `get(Object key)` Returns the entry to which this index maps the specified key.
`File` | `getIndexFile()` Returns index file.
`boolean` | `isValid()` Check is index file is valid.
`Iterator` | `keyIterator(Key key)`
`Iterator` | `nodeIterator(Key key)`
`Object` | `put(Object key, Object entry)` Associates the specified entry with the specified key in this index.
`Object` | `remove(Object key)` Removes the entry for this key from this index if present.
`int` | `size()` Returns the number of key-entry mappings in this index.

Methods inherited from class java.util.AbstractMap
`isEmpty, containsValue, putAll, keySet, values, equals, hashCode, toString`

Methods inherited from class java.lang.Object
`getClass, notify, notifyAll, wait, wait, wait`

Field Detail

### DEFAULT_BLOCK_SIZE

    public final static int DEFAULT_BLOCK_SIZE

  Default file block size.

### ROOT_BLOCK_OFFSET

    public final static int ROOT_BLOCK_OFFSET

  Root block offset

Constructor Detail

### BTreeIndex

    public BTreeIndex(File dataFile, String indexName, String indexPath, int blockSize)
                 throws java.io.IOException

  Construct index based on specified file. If index file already created and blockSize of file not equals specified blockSize, then all operations with index will be invalid and index file may be damaged.
  Parameters:
    dataFile - File for which index will be created. (or already created)
    indexName - Name of the index. Will be added to index file name.
    blockSize - Size of block for file operations.
  Throws:
    IOException - if an I/O error occurs.
  todo Extended Comments needed.

### BTreeIndex

    public BTreeIndex(File dataFile, String indexName, String indexPath)
                 throws java.io.IOException

  Create index with DEFAULT_BLOCK_SIZE.
  Parameters:
    dataFile - File for which index will be created. (or already created)
    indexName - Name of the index. Will be added to index file name.
  Throws:
    IOException - if an I/O error occurs.
  See Also:
    #BTreeIndex(File, String, int)
  todo Extended Comments needed.

Method Detail

### clear

    public void clear()

  Removes all keys and entries from this index. File stored key-entries recreates.
  Throws:
    ChainRuntimeException - if an I/O error occurs.

### close

    public void close()
                throws java.io.IOException

  Close this index and releases resources (index file). A closed index cannot perform any operations and cannot be reopened.
  Throws:
    IOException - if an I/O error occurs.

### containsKey

    public boolean containsKey(Object key)

  Returns `true` if this index contains entry for the specified key.
  Parameters:
    key - key whose presence in this index is to be tested.
  Returns: `true` if this index contains entry for the specified key.
  Throws:
    ClassCastException - if the key is not of type String.
    NullPointerException - key is `null` and this index does not permit `null` keys.
    ChainRuntimeException - if an I/O error occurs.

### createNode

    public Object createNode(byte[] buffer, int pos, String key, IndexEntry value)

### createNode

    public Object createNode(byte[] buffer, int pos)

### entrySet

    public Set entrySet()

  Returns a set view of the mappings contained in this index. Each element in the returned set is a `Map.Entry`. The set is backed by the index, so changes to the index are reflected in the set, and vice-versa. If the index is modified while an iteration over the set is in progress, the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the index, via the `Iterator.remove`, `Set.remove`, `removeAll`, `retainAll` and `clear` operations. It does not support the `add` or `addAll` operations.
  Returns: a set view of the mappings contained in this index.
  todo HIGH Test changes reflection!!!.

### get

    public Object get(Object key)

  Returns the entry to which this index maps the specified key. Returns `null` if the index contains no entry for this key.
  Parameters:
    key - key whose associated entry is to be returned.
  Returns: the entry to which this index maps the specified key, or `null` if the index not contains entry for this key.
  Throws:
    ClassCastException - if the key is not of type String.
    NullPointerException - key is `null` and this index does not permit `null` keys.
    ChainRuntimeException - if an I/O error occurs.
  See Also:
    Index.IndexEntry

### getIndexFile

    public File getIndexFile()

  Returns index file. This information is essential to remove index files.
  Returns: index file.

### isValid

    public boolean isValid()

  Check is index file is valid. Check existence and format of index file. If file corrupt you must clear index.
  See Also:
    clear()

### keyIterator

    public Iterator keyIterator(Key key)

### nodeIterator

    public Iterator nodeIterator(Key key)

### put

    public Object put(Object key, Object entry)

  Associates the specified entry with the specified key in this index. If the index previously contained entry for this key, the old entry is replaced.
  Parameters:
    _key - key with which the specified entry is to be associated.
    entry - entry to be associated with the specified key.
  Returns: previous entry associated with specified key, or `null` if there was no mapping for key.
  Throws:
    ClassCastException - if the key is not of type String. or entry is not of type Index.IndexEntry.
    IllegalArgumentException - if some aspect of this key or entry prevents it from being stored in this index.
    NullPointerException - this index does not permit `null` keys or entries, and the specified key or entry is `null`.
    ChainRuntimeException - if an I/O error occurs.

### remove

    public Object remove(Object key)

  Removes the entry for this key from this index if present.
  Parameters:
    key - key whose entry is to be removed from the index.
  Returns: previous entry associated with specified key, or `null` if there was no entry for key.
  Throws:
    ClassCastException - if the key is not of type String.
    ChainRuntimeException - if an I/O error occurs.

### size

    public int size()

  Returns the number of key-entry mappings in this index. If the index contains more than `Integer.MAX_VALUE` elements, returns `Integer.MAX_VALUE`.
  Returns: the number of key-entry mappings in this index.

Association Links

to Class ru.biosoft.access.BTreeIndex.NodeComparator

  Comparator for compare keys of nodes.

to Class java.io.File

  Name of index file

to Class java.io.RandomAccessFile

  Index file

to Class ru.biosoft.access.BTreeIndex.Block

  Root

to Class java.util.Map

  Cache

Overview | Package | Class | Use | Tree | Help
| FOOTER
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

BOTTOM