blob: 17c7a86730ef3b49b8628820fb22c9615a939543 (
plain) (
blame)
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
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.slime;
/**
* Light-weight index structure describing the layout of a Slime value
* encoded in binary format.
**/
final class DecodeIndex {
static final int initial_capacity = 16;
private long[] data = new long[initial_capacity];
private int reserved = 0;
private int adjustSize(int minSize) {
int capacity = initial_capacity;
while (capacity < minSize) {
capacity = capacity << 1;
}
return capacity;
}
int reserve(int n) {
int offset = reserved;
if (reserved + n > data.length) {
long[] old = data;
data = new long[adjustSize(reserved + n)];
System.arraycopy(old, 0, data, 0, reserved);
}
reserved += n;
return offset;
}
int size() { return reserved; }
void set(int idx, int byteOffset, int firstChild, int extBits) {
data[idx] = (long)(byteOffset & 0x7fff_ffff) << 33 |
(long)(firstChild & 0x7fff_ffff) << 2 |
extBits & 0x3;
}
int getByteOffset(int idx) {
return (int)(data[idx] >> 33) & 0x7fff_ffff;
}
int getFirstChild(int idx) {
return (int)(data[idx] >> 2) & 0x7fff_ffff;
}
int getExtBits(int idx) {
return (int)data[idx] & 0x3;
}
}
|