org.mapdb.serializer.SerializerInteger Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mapdb Show documentation
Show all versions of mapdb Show documentation
MapDB provides concurrent Maps, Sets and Queues backed by disk storage or off-heap memory. It is a fast, scalable and easy to use embedded Java database.
package org.mapdb.serializer;
import org.mapdb.DataInput2;
import org.mapdb.DataOutput2;
import java.io.IOException;
import java.util.Arrays;
import java.util.Comparator;
public class SerializerInteger extends SerializerFourByte {
@Override
public void serialize(DataOutput2 out, Integer value) throws IOException {
out.writeInt(value);
}
@Override
public Integer deserialize(DataInput2 in, int available) throws IOException {
return new Integer(in.readInt());
}
@Override
protected Integer unpack(int l) {
return new Integer(l);
}
@Override
protected int pack(Integer l) {
return l;
}
@Override
public int valueArraySearch(Object keys, Integer key) {
return Arrays.binarySearch((int[]) keys, key);
}
@Override
public int valueArrayBinarySearch(Integer key, DataInput2 input, int keysLen, Comparator comparator) throws IOException {
if (comparator != this)
return super.valueArrayBinarySearch(key, input, keysLen, comparator);
final int key2 = key;
for (int pos = 0; pos < keysLen; pos++) {
int from = input.readInt();
if (key2 <= from) {
input.skipBytes((keysLen-pos-1)*4);
return (key2 == from) ? pos : -(pos + 1);
}
}
//not found
return -(keysLen + 1);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy