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 int s
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
int s
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
int s 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
int s
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 IIntArraySlice
public final int off()
IIntArraySlice.array()
.
The offset of the slice into the backing byte[] is always zero.
off
in interface IIntArraySlice
public final int len()
IIntArraySlice.array()
.
The length of the slice is always the capacity of the backing byte[].
len
in interface IIntArraySlice
protected 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)
IManagedIntArray
ensureCapacity
in interface IManagedIntArray
capacity
- The minimum #of values in the buffer.public final int capacity()
IManagedIntArray
capacity
in interface IManagedIntArray
public final void put(int pos, int[] b)
IIntArraySlice
int
s in the caller's
array into this buffer starting at the specified position within the
slice defined by this buffer.put
in interface IIntArraySlice
pos
- 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)
IIntArraySlice
int
s
from the caller's array into this buffer starting at the specified
position within the slice defined by this buffer.put
in interface IIntArraySlice
pos
- 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 int
s to be copied.public final void get(int srcoff, int[] dst)
IIntArraySlice
dst.length
int
s
from the specified offset into the slice defined by this buffer into the
caller's array.get
in interface IIntArraySlice
srcoff
- 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)
IIntArraySlice
int
s
from this buffer into the specified slice of the caller's array.get
in interface IIntArraySlice
srcoff
- 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 int
s to be copied.public final void putInt(int pos, int v)
IIntArraySlice
putInt
in interface IIntArraySlice
pos
- The index.v
- The value.public final int getInt(int pos)
IIntArraySlice
getInt
in interface IIntArraySlice
pos
- The index.public final int[] toArray()
IIntArraySlice
toArray
in interface IIntArraySlice
public IIntArraySlice slice(int off, int len)
IIntArraySlice
IIntArraySlice.array()
, even when the buffer is extended and
the array reference is replaced.slice
in interface IIntArraySlice
off
- 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.