Package org.elasticsearch.common.util
Class BigArrays
- java.lang.Object
-
- org.elasticsearch.common.util.BigArrays
-
public class BigArrays extends java.lang.Object
Utility class to work with arrays.
-
-
Field Summary
Fields Modifier and Type Field Description static BigArrays
NON_RECYCLING_INSTANCE
-
Constructor Summary
Constructors Modifier Constructor Description BigArrays(PageCacheRecycler recycler, CircuitBreakerService breakerService, java.lang.String breakerName)
protected
BigArrays(PageCacheRecycler recycler, CircuitBreakerService breakerService, java.lang.String breakerName, boolean checkBreaker)
-
Method Summary
Modifier and Type Method Description CircuitBreakerService
breakerService()
boolean
equals(ByteArray array, ByteArray other)
ByteArray
grow(ByteArray array, long minSize)
Grow an array to a size that is larger thanminSize
, preserving content, and potentially reusing part of the provided array.DoubleArray
grow(DoubleArray array, long minSize)
Grow an array to a size that is larger thanminSize
, preserving content, and potentially reusing part of the provided array.FloatArray
grow(FloatArray array, long minSize)
Grow an array to a size that is larger thanminSize
, preserving content, and potentially reusing part of the provided array.IntArray
grow(IntArray array, long minSize)
Grow an array to a size that is larger thanminSize
, preserving content, and potentially reusing part of the provided array.LongArray
grow(LongArray array, long minSize)
Grow an array to a size that is larger thanminSize
, preserving content, and potentially reusing part of the provided array.<T> ObjectArray<T>
grow(ObjectArray<T> array, long minSize)
Grow an array to a size that is larger thanminSize
, preserving content, and potentially reusing part of the provided array.int
hashCode(ByteArray array)
ByteArray
newByteArray(long size)
Allocate a newByteArray
initialized with zeros.ByteArray
newByteArray(long size, boolean clearOnResize)
Allocate a newByteArray
.DoubleArray
newDoubleArray(long size)
Allocate a newDoubleArray
of the given capacity.DoubleArray
newDoubleArray(long size, boolean clearOnResize)
Allocate a newDoubleArray
.FloatArray
newFloatArray(long size)
Allocate a newFloatArray
of the given capacity.FloatArray
newFloatArray(long size, boolean clearOnResize)
Allocate a newFloatArray
.IntArray
newIntArray(long size)
Allocate a newIntArray
.IntArray
newIntArray(long size, boolean clearOnResize)
Allocate a newIntArray
.LongArray
newLongArray(long size)
Allocate a newLongArray
.LongArray
newLongArray(long size, boolean clearOnResize)
Allocate a newLongArray
.<T> ObjectArray<T>
newObjectArray(long size)
Allocate a newObjectArray
.static long
overSize(long minTargetSize)
Returns the next size to grow when working with parallel arrays that may have different page sizes or number of bytes per element.static long
overSize(long minTargetSize, int pageSize, int bytesPerElement)
Return the next size to grow to that is >=minTargetSize
.ByteArray
resize(ByteArray array, long size)
Resize the array to the exact provided size.DoubleArray
resize(DoubleArray array, long size)
Resize the array to the exact provided size.FloatArray
resize(FloatArray array, long size)
Resize the array to the exact provided size.IntArray
resize(IntArray array, long size)
Resize the array to the exact provided size.LongArray
resize(LongArray array, long size)
Resize the array to the exact provided size.<T> ObjectArray<T>
resize(ObjectArray<T> array, long size)
Resize the array to the exact provided size.BigArrays
withCircuitBreaking()
Return an instance of this BigArrays class with circuit breaking explicitly enabled, instead of only accounting enabled
-
-
-
Field Detail
-
NON_RECYCLING_INSTANCE
public static final BigArrays NON_RECYCLING_INSTANCE
-
-
Constructor Detail
-
BigArrays
public BigArrays(PageCacheRecycler recycler, @Nullable CircuitBreakerService breakerService, java.lang.String breakerName)
-
BigArrays
protected BigArrays(PageCacheRecycler recycler, @Nullable CircuitBreakerService breakerService, java.lang.String breakerName, boolean checkBreaker)
-
-
Method Detail
-
overSize
public static long overSize(long minTargetSize)
Returns the next size to grow when working with parallel arrays that may have different page sizes or number of bytes per element.
-
overSize
public static long overSize(long minTargetSize, int pageSize, int bytesPerElement)
Return the next size to grow to that is >=minTargetSize
. Inspired fromArrayUtil.oversize(int, int)
and adapted to play nicely with paging.
-
withCircuitBreaking
public BigArrays withCircuitBreaking()
Return an instance of this BigArrays class with circuit breaking explicitly enabled, instead of only accounting enabled
-
breakerService
public CircuitBreakerService breakerService()
-
newByteArray
public ByteArray newByteArray(long size, boolean clearOnResize)
Allocate a newByteArray
.- Parameters:
size
- the initial length of the arrayclearOnResize
- whether values should be set to 0 on initialization and resize
-
newByteArray
public ByteArray newByteArray(long size)
Allocate a newByteArray
initialized with zeros.- Parameters:
size
- the initial length of the array
-
resize
public ByteArray resize(ByteArray array, long size)
Resize the array to the exact provided size.
-
grow
public ByteArray grow(ByteArray array, long minSize)
Grow an array to a size that is larger thanminSize
, preserving content, and potentially reusing part of the provided array.
-
hashCode
public int hashCode(ByteArray array)
- See Also:
Arrays.hashCode(byte[])
-
equals
public boolean equals(ByteArray array, ByteArray other)
- See Also:
Arrays.equals(byte[], byte[])
-
newIntArray
public IntArray newIntArray(long size, boolean clearOnResize)
Allocate a newIntArray
.- Parameters:
size
- the initial length of the arrayclearOnResize
- whether values should be set to 0 on initialization and resize
-
newIntArray
public IntArray newIntArray(long size)
Allocate a newIntArray
.- Parameters:
size
- the initial length of the array
-
resize
public IntArray resize(IntArray array, long size)
Resize the array to the exact provided size.
-
grow
public IntArray grow(IntArray array, long minSize)
Grow an array to a size that is larger thanminSize
, preserving content, and potentially reusing part of the provided array.
-
newLongArray
public LongArray newLongArray(long size, boolean clearOnResize)
Allocate a newLongArray
.- Parameters:
size
- the initial length of the arrayclearOnResize
- whether values should be set to 0 on initialization and resize
-
newLongArray
public LongArray newLongArray(long size)
Allocate a newLongArray
.- Parameters:
size
- the initial length of the array
-
resize
public LongArray resize(LongArray array, long size)
Resize the array to the exact provided size.
-
grow
public LongArray grow(LongArray array, long minSize)
Grow an array to a size that is larger thanminSize
, preserving content, and potentially reusing part of the provided array.
-
newDoubleArray
public DoubleArray newDoubleArray(long size, boolean clearOnResize)
Allocate a newDoubleArray
.- Parameters:
size
- the initial length of the arrayclearOnResize
- whether values should be set to 0 on initialization and resize
-
newDoubleArray
public DoubleArray newDoubleArray(long size)
Allocate a newDoubleArray
of the given capacity.
-
resize
public DoubleArray resize(DoubleArray array, long size)
Resize the array to the exact provided size.
-
grow
public DoubleArray grow(DoubleArray array, long minSize)
Grow an array to a size that is larger thanminSize
, preserving content, and potentially reusing part of the provided array.
-
newFloatArray
public FloatArray newFloatArray(long size, boolean clearOnResize)
Allocate a newFloatArray
.- Parameters:
size
- the initial length of the arrayclearOnResize
- whether values should be set to 0 on initialization and resize
-
newFloatArray
public FloatArray newFloatArray(long size)
Allocate a newFloatArray
of the given capacity.
-
resize
public FloatArray resize(FloatArray array, long size)
Resize the array to the exact provided size.
-
grow
public FloatArray grow(FloatArray array, long minSize)
Grow an array to a size that is larger thanminSize
, preserving content, and potentially reusing part of the provided array.
-
newObjectArray
public <T> ObjectArray<T> newObjectArray(long size)
Allocate a newObjectArray
.- Parameters:
size
- the initial length of the array
-
resize
public <T> ObjectArray<T> resize(ObjectArray<T> array, long size)
Resize the array to the exact provided size.
-
grow
public <T> ObjectArray<T> grow(ObjectArray<T> array, long minSize)
Grow an array to a size that is larger thanminSize
, preserving content, and potentially reusing part of the provided array.
-
-