|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.deegree_impl.io.shpapi.DBaseIndex
A class for reading from and writing to DBase index files (*.ndx), maybe not 100% xbase compatible!
The fileformat is described at http://www.e-bachmann.dk/computing/databases/xbase/index.html
This index is suitable for indexing both unique and non-unique columns. Unique indexing is much faster than non-unique because it use a faster algorithm.
The index file is a B+tree (sometimes called a paged B-tree) that consist of pages. There are two page types, leaves and non-leafs. The starting page (eg. the page the search algorithm starts) is the root page.
Searching goes as follows:
Above algorithm is implemented in two different methods, one for unique indexes and one for non-unique indexes. Searching unique indexes is easier because the algorithm is finished as soon as it has found a key, the non-unique version of the algorithm has to find all keys present in the index.
Inserting goes as follows:
If a page that splits does not have a parent page then a new page is created. This page is the new starting page
Handling different data types: The index can handle strings and numbers. Numbers are always stored als IEEE doubles. The method addKey checks the given key and throws an exception if the datatype of the key doesn't suit the index
Nested Class Summary | |
class |
DBaseIndex.Cache
Inner class for the cache. |
private class |
DBaseIndex.KeyEntry
Inner class for the key entries |
private class |
DBaseIndex.Page
Inner class for the pages |
Field Summary | |
protected byte[] |
b
|
private DBaseIndex.Cache |
cache
|
protected int |
cacheSize
|
protected java.io.RandomAccessFile |
file
|
private java.lang.String |
fileName
|
protected byte[] |
keyBytes
|
protected int |
keyLength
|
protected int |
keyType
|
protected int |
noOfKeysPerPage
|
protected int |
numberOfPages
|
protected byte[] |
page
|
protected int |
sizeOfKeyRecord
|
protected int |
startingPageNo
|
private boolean |
uniqueFlag
|
Constructor Summary | |
|
DBaseIndex(java.lang.String name)
Open an existing .ndx file |
private |
DBaseIndex(java.lang.String name,
int startingPageNo,
int numberOfPages,
int sizeOfKeyRecord,
int keyLength,
int noOfKeysPerPage,
int keyType,
boolean uniqueFlag,
java.io.RandomAccessFile file)
Used by createIndex() |
Method Summary | |
void |
addKey(java.lang.Comparable key,
int record)
Add a key to the index |
void |
close()
Close the index file |
static DBaseIndex |
createIndex(java.lang.String name,
java.lang.String column,
int keyLength,
boolean uniqueFlag,
boolean numbers)
Create a new index |
void |
flush()
Flush all the buffers |
int |
getDepth()
Calculate the depth for the index |
protected DBaseIndex.Page |
getPage(int number)
Get a page |
boolean |
isUnique()
Contains this index unique values? |
protected DBaseIndex.Page |
newPage()
Create a new page |
int[] |
search(java.lang.Comparable key)
|
protected void |
setRoot(DBaseIndex.Page page)
Set the root page |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
private java.lang.String fileName
protected java.io.RandomAccessFile file
protected int startingPageNo
protected int numberOfPages
protected int sizeOfKeyRecord
protected int keyLength
protected int noOfKeysPerPage
protected int keyType
private boolean uniqueFlag
protected byte[] b
protected byte[] page
protected byte[] keyBytes
protected int cacheSize
private DBaseIndex.Cache cache
Constructor Detail |
public DBaseIndex(java.lang.String name) throws java.io.IOException
private DBaseIndex(java.lang.String name, int startingPageNo, int numberOfPages, int sizeOfKeyRecord, int keyLength, int noOfKeysPerPage, int keyType, boolean uniqueFlag, java.io.RandomAccessFile file)
Method Detail |
protected DBaseIndex.Page getPage(int number) throws java.io.IOException
java.io.IOException
protected DBaseIndex.Page newPage() throws java.io.IOException
java.io.IOException
protected void setRoot(DBaseIndex.Page page) throws java.io.IOException
java.io.IOException
public static DBaseIndex createIndex(java.lang.String name, java.lang.String column, int keyLength, boolean uniqueFlag, boolean numbers) throws java.io.IOException
java.io.IOException
public void flush() throws java.io.IOException
java.io.IOException
public void close() throws java.io.IOException
java.io.IOException
public int[] search(java.lang.Comparable key) throws java.io.IOException, KeyNotFoundException, InvalidKeyTypeException
java.io.IOException
KeyNotFoundException
InvalidKeyTypeException
public void addKey(java.lang.Comparable key, int record) throws java.io.IOException, KeyAlreadyExistException, InvalidKeyTypeException, KeyTooLongException
java.io.IOException
KeyAlreadyExistException
InvalidKeyTypeException
KeyTooLongException
public int getDepth() throws java.io.IOException
java.io.IOException
public boolean isUnique()
public java.lang.String toString()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |