class Packed64 extends PackedInts.MutableImpl
The implementation strives to perform as fast as possible under the constraint of contiguous bits, by avoiding expensive operations. This comes at the cost of code clarity.
Technical details: This implementation is a refinement of a non-branching version. The non-branching get and set methods meant that 2 or 4 atomics in the underlying array were always accessed, even for the cases where only 1 or 2 were needed. Even with caching, this had a detrimental effect on performance. Related to this issue, the old implementation used lookup tables for shifts and masks, which also proved to be a bit slower than calculating the shifts and masks on the fly. See https://issues.apache.org/jira/browse/LUCENE-4062 for details.
Modifier and Type | Field and Description |
---|---|
(package private) static int |
BLOCK_BITS |
(package private) static int |
BLOCK_SIZE |
private long[] |
blocks
Values are stores contiguously in the blocks array.
|
private int |
bpvMinusBlockSize
Optimization: Saves one lookup in
get(int) . |
private long |
maskRight
A right-aligned mask of width BitsPerValue used by
get(int) . |
(package private) static int |
MOD_MASK |
bitsPerValue, valueCount
Constructor and Description |
---|
Packed64(int packedIntsVersion,
DataInput in,
int valueCount,
int bitsPerValue)
Creates an array with content retrieved from the given DataInput.
|
Packed64(int valueCount,
int bitsPerValue)
Creates an array with the internal structures adjusted for the given
limits and initialized to 0.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Sets all values to 0.
|
void |
fill(int fromIndex,
int toIndex,
long val)
Fill the mutable from
fromIndex (inclusive) to
toIndex (exclusive) with val . |
private static int |
gcd(int a,
int b) |
long |
get(int index)
Get the long at the given index.
|
int |
get(int index,
long[] arr,
int off,
int len)
Bulk get: read at least one and at most
len longs starting
from index into arr[off:off+len] and return
the actual number of values that have been read. |
long |
ramBytesUsed()
Return the memory usage of this object in bytes.
|
void |
set(int index,
long value)
Set the value at the given index in the array.
|
int |
set(int index,
long[] arr,
int off,
int len)
Bulk set: set at least one and at most
len longs starting
at off in arr into this mutable, starting at
index . |
java.lang.String |
toString() |
getBitsPerValue, size
getFormat, save
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getChildResources
static final int BLOCK_SIZE
static final int BLOCK_BITS
static final int MOD_MASK
private final long[] blocks
private final long maskRight
get(int)
.private final int bpvMinusBlockSize
get(int)
.public Packed64(int valueCount, int bitsPerValue)
valueCount
- the number of elements.bitsPerValue
- the number of bits available for any given value.public Packed64(int packedIntsVersion, DataInput in, int valueCount, int bitsPerValue) throws java.io.IOException
in
- a DataInput, positioned at the start of Packed64-content.valueCount
- the number of elements.bitsPerValue
- the number of bits available for any given value.java.io.IOException
- if the values for the backing array could not
be retrieved.public long get(int index)
PackedInts.Reader
get
in class PackedInts.Reader
index
- the position of the value.public int get(int index, long[] arr, int off, int len)
PackedInts.Reader
len
longs starting
from index
into arr[off:off+len]
and return
the actual number of values that have been read.get
in class PackedInts.Reader
public void set(int index, long value)
PackedInts.Mutable
set
in class PackedInts.Mutable
index
- where the value should be positioned.value
- a value conforming to the constraints set by the array.public int set(int index, long[] arr, int off, int len)
PackedInts.Mutable
len
longs starting
at off
in arr
into this mutable, starting at
index
. Returns the actual number of values that have been
set.set
in class PackedInts.Mutable
public java.lang.String toString()
toString
in class PackedInts.MutableImpl
public long ramBytesUsed()
Accountable
public void fill(int fromIndex, int toIndex, long val)
PackedInts.Mutable
fromIndex
(inclusive) to
toIndex
(exclusive) with val
.fill
in class PackedInts.Mutable
private static int gcd(int a, int b)
public void clear()
PackedInts.Mutable
clear
in class PackedInts.Mutable