public final class CachedRecords
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private byte[] |
buffer |
private int |
buffercount |
private byte[] |
cache |
private int |
cachecount
number of entries in buffer
|
private long |
cacheindex |
private static int |
maxReadCache
stay below hard disc cache (is that necessary?)
|
private static int |
maxWriteBuffer |
private java.io.RandomAccessFile |
raf |
protected int |
recordsize
number of bytes in one record
|
private java.io.File |
tablefile |
private byte[] |
zero |
Constructor and Description |
---|
CachedRecords(java.io.File tablefile,
int recordsize) |
Modifier and Type | Method and Description |
---|---|
void |
add(byte[] b,
int start) |
void |
clean(long index) |
void |
cleanLast() |
void |
cleanLast(byte[] b,
int start) |
private void |
cleanLast0() |
private void |
cleanLast0(byte[] b,
int start)
this is like
clean(this.size() - 1, b, start); |
void |
close() |
void |
deleteOnExit() |
java.io.File |
filename() |
private long |
filesize() |
private void |
fillCache(long index)
load cache with copy of disc content; start with record at index
if the record would overlap with the write buffer,
its start is shifted forward until it fits
|
static void |
fixTableSize(java.io.File tablefile,
long recordsize) |
void |
flushBuffer()
write buffer to end of file
|
void |
get(long index,
byte[] b,
int start) |
private int |
inBuffer(long index)
checks if the index is inside the buffer
|
private int |
inCache(long index)
checks if the index is inside the cache
|
private static boolean |
isClean(byte[] b,
int offset,
int length) |
private boolean |
isClean(long index) |
static void |
main(java.lang.String[] args)
main - writes some data and checks the tables size (with time measureing)
|
void |
put(long index,
byte[] b,
int start) |
long |
size() |
static long |
tableSize(java.io.File tablefile,
long recordsize) |
private java.io.RandomAccessFile raf
private final java.io.File tablefile
protected final int recordsize
private long cacheindex
private int cachecount
private int buffercount
private byte[] cache
private byte[] buffer
private final byte[] zero
private static final int maxReadCache
private static final int maxWriteBuffer
public CachedRecords(java.io.File tablefile, int recordsize) throws java.io.IOException
java.io.IOException
public static final long tableSize(java.io.File tablefile, long recordsize) throws java.io.IOException
tablefile
- recordsize
- java.io.IOException
public static final void fixTableSize(java.io.File tablefile, long recordsize) throws java.io.IOException
java.io.IOException
public final long size() throws java.io.IOException
java.io.IOException
public final java.io.File filename()
private final long filesize() throws java.io.IOException
java.io.IOException
private final int inCache(long index)
index
- private final int inBuffer(long index) throws java.io.IOException
index
- java.io.IOException
private final void fillCache(long index) throws java.io.IOException
index
- java.io.IOException
public final void flushBuffer()
public final void close()
public final void get(long index, byte[] b, int start) throws java.io.IOException
index
- record which should be readb
- destination arraystart
- offset in b to store datajava.io.IOException
public final void put(long index, byte[] b, int start) throws java.io.IOException
java.io.IOException
public final void add(byte[] b, int start) throws java.io.IOException
java.io.IOException
private static final boolean isClean(byte[] b, int offset, int length)
private final boolean isClean(long index) throws java.io.IOException
java.io.IOException
public final void clean(long index) throws java.io.IOException
index
- java.io.IOException
clean(long, byte[], int)
public final void cleanLast(byte[] b, int start) throws java.io.IOException
b
- start
- java.io.IOException
clean(long, byte[], int)
private final void cleanLast0(byte[] b, int start) throws java.io.IOException
clean(this.size() - 1, b, start);
b
- start
- java.io.IOException
clean(long, byte[], int)
public final void cleanLast() throws java.io.IOException
java.io.IOException
clean(long, byte[], int)
private final void cleanLast0() throws java.io.IOException
java.io.IOException
public final void deleteOnExit()
public static void main(java.lang.String[] args)
args
-