com.unister.semweb.drums.file
Class IndexForHeaderIndexFile

java.lang.Object
  extended by com.unister.semweb.drums.file.IndexForHeaderIndexFile

public class IndexForHeaderIndexFile
extends java.lang.Object

This class represents a sparse index for one HeaderIndexFile. It writes its updates to the given MappedByteBuffer. A IndexForHeaderIndexFile knows for each defined chunk the largest key. If the elements are ordered in some manner this allows fast access.

Example, 3 Chunks, the third chunk is not fully filled:
------- 10 | ----------- 50 | -- 200 |
1 2 4 5 10 | 11 23 32 49 50 | 51 200 |

Author:
Martin Nettling

Constructor Summary
IndexForHeaderIndexFile(int numberOfChunks, int keySize, int chunkSize, java.nio.ByteBuffer indexBuffer)
          This constructor instantiates a new IndexForHeaderIndexFile.
 
Method Summary
 int getChunkId(byte[] key)
          returns the index of the chunk, where the element could be found.
 long getStartOffsetOfChunk(int chunkIndex)
          returns the position of chunk with the given index in the file.
 long getStartOffsetOfChunkByKey(byte[] key)
          returns the position in the file, where the chunk, where the key belongs to starts.
 boolean isConsistent()
          Checks, if this index is consistent.
 void setLargestKey(int chunkIdx, byte[] largestKeyInChunk)
          Sets a new largest key in the chunk with the given index.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IndexForHeaderIndexFile

public IndexForHeaderIndexFile(int numberOfChunks,
                               int keySize,
                               int chunkSize,
                               java.nio.ByteBuffer indexBuffer)
This constructor instantiates a new IndexForHeaderIndexFile. You need to give the number of the indexed chunks, the chunksize and the MappedByteBuffer, where the index should be written to.

Parameters:
numberOfChunks - the expected or maximal number of chunks
keySize -
chunkSize - the size of one chunk
indexBuffer - the buffer were to write the indexinformations
Method Detail

getStartOffsetOfChunk

public long getStartOffsetOfChunk(int chunkIndex)
returns the position of chunk with the given index in the file.

Parameters:
chunkIndex -
Returns:
long, the byte-offset of the chunk

getStartOffsetOfChunkByKey

public long getStartOffsetOfChunkByKey(byte[] key)
returns the position in the file, where the chunk, where the key belongs to starts.

Parameters:
key -
Returns:
long, the byte-offset of the chunk

getChunkId

public int getChunkId(byte[] key)
returns the index of the chunk, where the element could be found. If the element can't be in one of the chunks the method will return -1.

Parameters:
key - the key to look for
Returns:
the id of the chunk, where the key could be found. If there is no putative chunk, then -1 will returned.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

isConsistent

public boolean isConsistent()
Checks, if this index is consistent. All inserted keys have to be inserted incrementally.

Returns:
boolean

setLargestKey

public void setLargestKey(int chunkIdx,
                          byte[] largestKeyInChunk)
Sets a new largest key in the chunk with the given index.

Parameters:
chunkIdx -
largestKeyInChunk -