if (this.sizeValues > 0) {
this.sizeValues-=numberOfKeyElements;
}
long addressOfPreviousKey = 0;
try {
final PageAddress pageAddress = new PageAddress(0, this.pointersFilename);
final byte[] page = BufferManager.getBufferManager().getPage(this.TABLEPAGESIZE, pageAddress);
final int hashAddress = Math.abs(thiskey.hashCode()) % this.TABLESIZE;
long pointer = InputHelper.readLuposLong(new ByteArrayInputStream(page, hashAddress * 8, 8));
// check existing list of entries for this table position
Quadruple<K, Long, Long, Long> entry;
boolean found = false;
do {
entry = this.getKey(pointer);
if(entry.getFourth() == addressOfFoundKey) {
// found!
addressOfPreviousKey = pointer;
found = true;
}
if((entry.getFourth() == 0)) {
found = true;
}
// go to next entry in list...
pointer = entry.getFourth();
} while(!found);
} catch (final IOException e) {
System.err.println(e);
e.printStackTrace();
}
// check if key is first entry in key list
if (addressOfPreviousKey == 0) {
// check if key is last entry in key list
if (this.getKey(addressOfFoundKey).getFourth() == 0){
try {
final PageAddress pageAddress = new PageAddress(0, this.pointersFilename);
final byte[] page = BufferManager.getBufferManager().getPage(this.TABLEPAGESIZE, pageAddress);
final int hashAddress = Math.abs(thiskey.hashCode()) % this.TABLESIZE;
final OutputStream outKeys = new ExistingByteArrayOutputStream(page, hashAddress * 8);
OutHelper.writeLuposLong(0, outKeys);
outKeys.close();
BufferManager.getBufferManager().modifyPage(this.TABLEPAGESIZE, pageAddress, page);
} catch (final IOException e) {
System.err.println(e);
e.printStackTrace();
}
} // key is not last entry in key list
else {
try {
final PageAddress pageAddressPointers = new PageAddress(0, this.pointersFilename);
final byte[] pagePointers = BufferManager.getBufferManager().getPage(this.TABLEPAGESIZE, pageAddressPointers);
final int hashAddress = Math.abs(thiskey.hashCode()) % this.TABLESIZE;
final OutputStream outKeys = new ExistingByteArrayOutputStream(pagePointers, hashAddress * 8);