forked from jankotek/mapdb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLongSerializer.java
More file actions
67 lines (52 loc) · 1.48 KB
/
Copy pathLongSerializer.java
File metadata and controls
67 lines (52 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package org.mapdb.ser;
import org.jetbrains.annotations.Nullable;
import org.mapdb.io.DataInput2;
import org.mapdb.io.DataOutput2;
import java.io.IOException;
import java.util.Arrays;
import java.util.Comparator;
/**
* Created by jan on 2/28/16.
*/
public class LongSerializer extends EightByteSerializer<Long> {
@Override
public void serialize(DataOutput2 out, Long value) {
out.writeLong(value);
}
@Override
public Long deserialize(DataInput2 in) {
return new Long(in.readLong());
}
@Nullable
@Override
public Class serializedType() {
return long[].class;
}
@Override
protected Long unpack(long l) {
return new Long(l);
}
@Override
protected long pack(Long l) {
return l.longValue();
}
@Override
public int valueArraySearch(long[] keys, Long key) {
return Arrays.binarySearch((long[])keys, key);
}
@Override
public int valueArrayBinarySearch(Long key, DataInput2 input, int keysLen, Comparator comparator) {
if (comparator != this)
return super.valueArrayBinarySearch(key, input, keysLen, comparator);
long key2 = key;
for (int pos = 0; pos < keysLen; pos++) {
long from = input.readLong();
if (key2 <= from) {
input.skipBytes((keysLen-pos-1)*8);
return (key2 == from) ? pos : -(pos + 1);
}
}
//not found
return -(keysLen + 1);
}
}