public class ManagedIntArray extends Object implements IManagedIntArray
Note: The backing int[] always has an offset of ZERO (0) and a
length equal to the capacity of the backing int[].
This class is NOT thread-safe for mutation. The operation which replaces the
array() when the capacity of the backing buffer must be extended is
not atomic.
| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_INITIAL_CAPACITY
The default capacity of the buffer.
|
| Constructor and Description |
|---|
ManagedIntArray()
Creates a buffer with an initial capacity of
128 bytes.
|
ManagedIntArray(int initialCapacity)
Creates a buffer with the specified initial capacity.
|
ManagedIntArray(int[] array)
Create a view wrapping the entire array.
|
| Modifier and Type | Method and Description |
|---|---|
int[] |
array()
The backing array.
|
protected static int |
assertNonNegative(String msg,
int v)
Throws exception unless the value is non-negative.
|
int |
capacity()
Return the capacity of the backing buffer.
|
void |
ensureCapacity(int capacity)
Ensure that the buffer capacity is a least capacity total values.
|
void |
get(int srcoff,
int[] dst)
Absolute bulk get copies
dst.length ints
from the specified offset into the slice defined by this buffer into the
caller's array. |
void |
get(int srcoff,
int[] dst,
int dstoff,
int dstlen)
Absolute bulk get copies the specified slice of
ints
from this buffer into the specified slice of the caller's array. |
int |
getInt(int pos)
Absolute get of a value at an index.
|
int |
len()
The length of the slice in the
IIntArraySlice.array(). |
int |
off()
The start of the slice in the
IIntArraySlice.array(). |
void |
put(int pos,
int[] b)
Absolute bulk put copies all
ints in the caller's
array into this buffer starting at the specified position within the
slice defined by this buffer. |
void |
put(int pos,
int[] b,
int off,
int len)
Absolute bulk put copies the specified slice of
ints
from the caller's array into this buffer starting at the specified
position within the slice defined by this buffer. |
void |
putInt(int pos,
int v)
Absolute put of a value at an index.
|
IIntArraySlice |
slice(int off,
int len)
Return a slice of the backing buffer.
|
int[] |
toArray()
Return a copy of the data in the slice.
|
public static final int DEFAULT_INITIAL_CAPACITY
public ManagedIntArray()
public ManagedIntArray(int initialCapacity)
initialCapacity - The initial capacity.public ManagedIntArray(int[] array)
Note: the caller's reference will be used until and unless the array is grown, at which point the caller's reference will be replaced by a larger array having the same data.
array - The array.public final int[] array()
array in interface IIntArraySlicepublic final int off()
IIntArraySlice.array().
The offset of the slice into the backing byte[] is always zero.
off in interface IIntArraySlicepublic final int len()
IIntArraySlice.array().
The length of the slice is always the capacity of the backing byte[].
len in interface IIntArraySliceprotected static int assertNonNegative(String msg, int v)
msg - The exception message.v - The value.IllegalArgumentException - unless the value is non-negative.public final void ensureCapacity(int capacity)
IManagedIntArrayensureCapacity in interface IManagedIntArraycapacity - The minimum #of values in the buffer.public final int capacity()
IManagedIntArraycapacity in interface IManagedIntArraypublic final void put(int pos,
int[] b)
IIntArraySliceints in the caller's
array into this buffer starting at the specified position within the
slice defined by this buffer.put in interface IIntArraySlicepos - The starting position within the slice defined by this buffer.b - The source data.public final void put(int pos,
int[] b,
int off,
int len)
IIntArraySliceints
from the caller's array into this buffer starting at the specified
position within the slice defined by this buffer.put in interface IIntArraySlicepos - The offset into the slice to which the data will be copied.b - The source data.off - The offset of the 1st int in the source data to
be copied.len - The #of ints to be copied.public final void get(int srcoff,
int[] dst)
IIntArraySlicedst.length ints
from the specified offset into the slice defined by this buffer into the
caller's array.get in interface IIntArraySlicesrcoff - The offset into the slice of the first int to be copied.dst - The array into which the data will be copied.public final void get(int srcoff,
int[] dst,
int dstoff,
int dstlen)
IIntArraySliceints
from this buffer into the specified slice of the caller's array.get in interface IIntArraySlicesrcoff - The offset into the slice defined by this buffer of the first
int to be copied.dst - The array into which the data will be copied.dstoff - The offset of the first int in that array onto
which the data will be copied.dstlen - The #of ints to be copied.public final void putInt(int pos,
int v)
IIntArraySliceputInt in interface IIntArraySlicepos - The index.v - The value.public final int getInt(int pos)
IIntArraySlicegetInt in interface IIntArraySlicepos - The index.public final int[] toArray()
IIntArraySlicetoArray in interface IIntArraySlicepublic IIntArraySlice slice(int off, int len)
IIntArraySliceIIntArraySlice.array(), even when the buffer is extended and
the array reference is replaced.slice in interface IIntArraySliceoff - The starting offset into the backing buffer of the slice.len - The length of that slice.Copyright © 2006–2019 SYSTAP, LLC DBA Blazegraph. All rights reserved.