|
|
|
@ -24,87 +24,68 @@
|
|
|
|
|
|
|
|
|
|
package de.anomic.kelondro;
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
|
|
|
|
|
//import java.util.Random;
|
|
|
|
|
|
|
|
|
|
public class kelondroIntBytesMap {
|
|
|
|
|
|
|
|
|
|
private kelondroIndex index;
|
|
|
|
|
private kelondroRowSet index;
|
|
|
|
|
|
|
|
|
|
public kelondroIntBytesMap(int payloadSize, int initSize) {
|
|
|
|
|
index = new kelondroRowSet(new kelondroRow("Cardinal key-4 {b256}, byte[] payload-" + payloadSize, kelondroNaturalOrder.naturalOrder, 0), initSize);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int size() {
|
|
|
|
|
try {
|
|
|
|
|
return index.size();
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
return index.size();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public long memoryNeededForGrow() {
|
|
|
|
|
return index.memoryNeededForGrow();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public byte[] getb(int ii) {
|
|
|
|
|
kelondroRow.Entry indexentry;
|
|
|
|
|
try {indexentry = index.get(kelondroNaturalOrder.encodeLong((long) ii, 4));} catch (IOException e) {return null;}
|
|
|
|
|
indexentry = index.get(kelondroNaturalOrder.encodeLong((long) ii, 4));
|
|
|
|
|
if (indexentry == null) return null;
|
|
|
|
|
return indexentry.getColBytes(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void addb(int ii, byte[] value) {
|
|
|
|
|
kelondroRow.Entry newentry;
|
|
|
|
|
try {
|
|
|
|
|
newentry = index.row().newEntry();
|
|
|
|
|
newentry.setCol(0, (long) ii);
|
|
|
|
|
newentry.setCol(1, value);
|
|
|
|
|
index.addUnique(newentry);
|
|
|
|
|
} catch (IOException e) {}
|
|
|
|
|
newentry = index.row().newEntry();
|
|
|
|
|
newentry.setCol(0, (long) ii);
|
|
|
|
|
newentry.setCol(1, value);
|
|
|
|
|
index.addUnique(newentry);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public byte[] putb(int ii, byte[] value) {
|
|
|
|
|
kelondroRow.Entry newentry;
|
|
|
|
|
try {
|
|
|
|
|
newentry = index.row().newEntry();
|
|
|
|
|
newentry.setCol(0, (long) ii);
|
|
|
|
|
newentry.setCol(1, value);
|
|
|
|
|
kelondroRow.Entry oldentry = index.put(newentry);
|
|
|
|
|
if (oldentry == null) return null;
|
|
|
|
|
return oldentry.getColBytes(1);
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
newentry = index.row().newEntry();
|
|
|
|
|
newentry.setCol(0, (long) ii);
|
|
|
|
|
newentry.setCol(1, value);
|
|
|
|
|
kelondroRow.Entry oldentry = index.put(newentry);
|
|
|
|
|
if (oldentry == null) return null;
|
|
|
|
|
return oldentry.getColBytes(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public byte[] removeb(int ii) {
|
|
|
|
|
try {
|
|
|
|
|
if (index.size() == 0) return null;
|
|
|
|
|
kelondroRow.Entry indexentry = index.remove(kelondroNaturalOrder.encodeLong((long) ii, 4));
|
|
|
|
|
if (indexentry == null) return null;
|
|
|
|
|
return indexentry.getColBytes(1);
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
if (index.size() == 0) return null;
|
|
|
|
|
kelondroRow.Entry indexentry = index.remove(kelondroNaturalOrder.encodeLong((long) ii, 4));
|
|
|
|
|
if (indexentry == null) return null;
|
|
|
|
|
return indexentry.getColBytes(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public byte[] removeoneb() {
|
|
|
|
|
try {
|
|
|
|
|
if (index.size() == 0) return null;
|
|
|
|
|
kelondroRow.Entry indexentry = index.removeOne();
|
|
|
|
|
if (indexentry == null) return null;
|
|
|
|
|
return indexentry.getColBytes(1);
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
if (index.size() == 0) return null;
|
|
|
|
|
kelondroRow.Entry indexentry = index.removeOne();
|
|
|
|
|
if (indexentry == null) return null;
|
|
|
|
|
return indexentry.getColBytes(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Iterator rows() {
|
|
|
|
|
try {
|
|
|
|
|
return index.rows(true, null);
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return index.rows(true, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void flush() {
|
|
|
|
|