Class SimpleVector<E>
- java.lang.Object
-
- gnu.lists.AbstractSequence<E>
-
- gnu.lists.SimpleVector<E>
-
- All Implemented Interfaces:
BoundedHashable
,Array<E>
,AVector<E>
,Consumable
,Sequence<E>
,Externalizable
,Serializable
,Iterable<E>
,Collection<E>
,List<E>
,RandomAccess
- Direct Known Subclasses:
AbstractCharVector
,BitVector
,F32Vector
,F64Vector
,FVector
,Nodes.NodeVector
,PrimIntegerVector
public abstract class SimpleVector<E> extends AbstractSequence<E> implements AVector<E>, Externalizable, RandomAccess
A generic simple vector. This is normally a wrapper around a plain Java array, the "data buffer", which is the value of codegetBuffer()
. (FUTURE: could be a wrapper around a String?) The elements of the vector (viewed as a java.util.List) are stored in order, in the array, in one of these modes:Very-simple mode: All of elements of the data buffer are used. Normally
get(i)
is the @code{i}'th element of the data buffer. An exception: For a CharSequence (FString), the value ofget(i)
is a Unicode code point, so it is found at offset computed byCharacter.offsetByCodePoints(i)
.Sub-range mode: The elements of this vector are a contiguous sub-range of the data buffer, given by a start offset and a size. This is used for creating a read-only sub-list with sharing of the data buffer. The original is made copy-on-write.
Gap-buffer mode: The elements of this vector are in two contiguous sub-range of the data buffer, one at the very start of the buffer, and one at the very end, with an unused gap between them. (The gap and either sub-range may be empty.)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected static long
COPY_ON_WRITE
protected static long
GAP_FLAG
protected long
info
static int
MAX_GAP_SIZE
protected static long
READ_ONLY_FLAG
protected static long
SHARED_FLAG
protected static long
SUBRANGE_FLAG
protected static long
VERY_SIMPLE_FLAG
-
Fields inherited from class gnu.lists.AbstractSequence
noInts
-
Fields inherited from interface gnu.lists.Sequence
ATTRIBUTE_VALUE, BOOLEAN_VALUE, CDATA_VALUE, CHAR_VALUE, COMMENT_VALUE, DOCUMENT_VALUE, DOUBLE_VALUE, ELEMENT_VALUE, EOF_VALUE, eofValue, FLOAT_VALUE, INT_S16_VALUE, INT_S32_VALUE, INT_S64_VALUE, INT_S8_VALUE, INT_U16_VALUE, INT_U32_VALUE, INT_U64_VALUE, INT_U8_VALUE, OBJECT_VALUE, PRIM_VALUE, PROCESSING_INSTRUCTION_VALUE, TEXT_BYTE_VALUE
-
-
Constructor Summary
Constructors Constructor Description SimpleVector()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
add(int index, E o)
See java.util.List.boolean
add(E o)
See java.util.Collection.protected int
addPos(int ipos, E value)
Add a value at a specified Pos.protected void
addSpace(int index, int count)
Insert count unspecified elements at index.SimpleVector<E>
asImmutable()
protected void
checkCanWrite()
protected abstract void
clearBuffer(int start, int count)
abstract void
copyBuffer(int length)
void
delete(int start, int end)
protected void
doCopyOnWrite(int sz)
int
effectiveIndex(int index)
void
fill(E value)
void
forEach(Consumer<? super E> action)
protected void
gapReserve(int where, int needed)
protected void
gapReserveGeneric(int where, int needed)
protected abstract Object
getBuffer()
abstract int
getBufferLength()
protected int
getGapEnd()
protected int
getGapSize()
protected int
getGapStart()
protected int
getOffsetBits()
E
getRowMajor(int i)
long
getSegment(int index)
Get sub-range of this vector, starting at given index.int
getSegment(int index, int len)
int
getSegmentReadOnly(int start, int len)
protected int
getSizeBits()
String
getTag()
This is convenience hack for printing "uniform vectors" (srfi 4).protected boolean
isAfterPos(int ipos)
Tests whether the position has the "isAfter" property.protected boolean
isGapBuffer()
The values arebuffer[0 <: size] ++ buffer[gapEnd <: ]
, where gapEnd = size + offsetboolean
isReadOnly()
protected boolean
isSubRange()
The values arebuffer[offset <: offset+size]
.protected boolean
isVerySimple()
If isSimple(), the values are all the values of the buffer.protected abstract SimpleVector
newInstance(int newSize)
void
readExternal(ObjectInput in)
protected abstract void
setBuffer(Object obj)
protected void
setGapBounds(int gapStart, int gapEnd)
protected void
setGapBounds(int gapStart, int gapEnd, long flags)
protected void
setInfoField(int size, int offset, long flags)
void
setReadOnly()
void
shift(int srcStart, int dstStart, int count)
int
size()
See java.util.List.Object
toDataArray()
protected int
vsize()
void
writeExternal(ObjectOutput out)
-
Methods inherited from class gnu.lists.AbstractSequence
addAll, addAll, badRank, boundedHash, checkRank, clear, compare, compare, compare, consume, consume, consumeNext, consumePosRange, contains, containsAll, copyPos, createPos, createRelativePos, effectiveIndex, effectiveIndex, effectiveIndex, effectiveIndex, elements, endPos, equals, equals, fill, fillPosRange, firstAttributePos, firstChildPos, firstChildPos, fromEndIndex, get, get, get, get, get, getAttribute, getAttributeLength, getBooleanRaw, getByteRaw, getCharRaw, getContainingSequenceSize, getDoubleRaw, getElementKind, getFloatRaw, getIndexDifference, getInt, getInt, getInt, getInt, getInt, getIntRaw, getIterator, getIterator, getIteratorAtPos, getLongRaw, getLowBound, getNextKind, getNextTypeName, getNextTypeObject, getPosNext, getPosPrevious, getRaw, getShortRaw, getSize, getSize, gotoAttributesStart, gotoChildrenStart, gotoParent, hashCode, hasNext, hasPrevious, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, nextIndex, nextIndex, nextMatching, nextPos, parentPos, previousPos, rank, releasePos, remove, remove, removeAll, removePos, removePosRange, retainAll, set, set, setAt, setPosNext, setPosPrevious, setRaw, stableCompare, startPos, subList, subSequence, subSequencePos, toArray, toArray, toString, toString, unsupported, unsupportedException
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface gnu.lists.Array
effectiveIndex, effectiveIndex, effectiveIndex, effectiveIndex, get, get, get, get, get, getBooleanRaw, getByteRaw, getCharRaw, getDoubleRaw, getElementKind, getFloatRaw, getInt, getInt, getInt, getInt, getInt, getIntRaw, getLongRaw, getLowBound, getRaw, getShortRaw, getSize, getSize, isEmpty, rank, set, setRaw
-
Methods inherited from interface gnu.kawa.util.BoundedHashable
boundedHash
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Methods inherited from interface gnu.lists.Consumable
consume
-
Methods inherited from interface java.util.List
addAll, addAll, clear, contains, containsAll, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, replaceAll, retainAll, sort, spliterator, subList, toArray, toArray
-
-
-
-
Field Detail
-
info
protected long info
-
MAX_GAP_SIZE
public static final int MAX_GAP_SIZE
- See Also:
- Constant Field Values
-
READ_ONLY_FLAG
protected static final long READ_ONLY_FLAG
- See Also:
- Constant Field Values
-
SHARED_FLAG
protected static final long SHARED_FLAG
- See Also:
- Constant Field Values
-
COPY_ON_WRITE
protected static final long COPY_ON_WRITE
- See Also:
- Constant Field Values
-
SUBRANGE_FLAG
protected static final long SUBRANGE_FLAG
- See Also:
- Constant Field Values
-
GAP_FLAG
protected static final long GAP_FLAG
- See Also:
- Constant Field Values
-
VERY_SIMPLE_FLAG
protected static final long VERY_SIMPLE_FLAG
- See Also:
- Constant Field Values
-
-
Method Detail
-
isVerySimple
protected final boolean isVerySimple()
If isSimple(), the values are all the values of the buffer. In this case getSize() == getBufferLength();
-
isSubRange
protected final boolean isSubRange()
The values arebuffer[offset <: offset+size]
.
-
isGapBuffer
protected final boolean isGapBuffer()
The values arebuffer[0 <: size] ++ buffer[gapEnd <: ]
, where gapEnd = size + offset
-
setInfoField
protected final void setInfoField(int size, int offset, long flags)
-
getGapStart
protected final int getGapStart()
-
getGapEnd
protected final int getGapEnd()
-
getGapSize
protected final int getGapSize()
-
setGapBounds
protected final void setGapBounds(int gapStart, int gapEnd, long flags)
-
setGapBounds
protected final void setGapBounds(int gapStart, int gapEnd)
-
getSizeBits
protected final int getSizeBits()
-
getOffsetBits
protected final int getOffsetBits()
-
isReadOnly
public boolean isReadOnly()
-
setReadOnly
public void setReadOnly()
-
size
public int size()
Description copied from interface:Sequence
See java.util.List.
-
vsize
protected int vsize()
-
effectiveIndex
public int effectiveIndex(int index)
- Specified by:
effectiveIndex
in interfaceArray<E>
- Overrides:
effectiveIndex
in classAbstractSequence<E>
-
gapReserve
protected void gapReserve(int where, int needed)
-
gapReserveGeneric
protected final void gapReserveGeneric(int where, int needed)
-
setBuffer
protected abstract void setBuffer(Object obj)
- Overrides:
setBuffer
in classAbstractSequence<E>
-
getBufferLength
public abstract int getBufferLength()
-
copyBuffer
public abstract void copyBuffer(int length)
-
newInstance
protected abstract SimpleVector newInstance(int newSize)
-
asImmutable
public SimpleVector<E> asImmutable()
- Specified by:
asImmutable
in interfaceArray<E>
- Overrides:
asImmutable
in classAbstractSequence<E>
-
checkCanWrite
protected void checkCanWrite()
- Overrides:
checkCanWrite
in classAbstractSequence<E>
-
doCopyOnWrite
protected void doCopyOnWrite(int sz)
-
getSegment
public long getSegment(int index)
Get sub-range of this vector, starting at given index.- Returns:
(size<<32)|where
such thatget(i)
isdata[where]
;get(i+1)
isdata[where+1]
; untilget(i+size-1)
. Thesize
is at least 1 (unlessindex==size()
), but we try to do better.
-
getSegment
public int getSegment(int index, int len)
-
getSegmentReadOnly
public int getSegmentReadOnly(int start, int len)
-
isAfterPos
protected boolean isAfterPos(int ipos)
Description copied from class:AbstractSequence
Tests whether the position has the "isAfter" property. I.e. if something is inserted at the position, will the iterator end up being after the new data?- Overrides:
isAfterPos
in classAbstractSequence<E>
-
getBuffer
protected abstract Object getBuffer()
-
getRowMajor
public E getRowMajor(int i)
- Specified by:
getRowMajor
in interfaceArray<E>
- Overrides:
getRowMajor
in classAbstractSequence<E>
-
fill
public void fill(E value)
-
shift
public void shift(int srcStart, int dstStart, int count)
-
add
public boolean add(E o)
Description copied from class:AbstractSequence
See java.util.Collection.- Specified by:
add
in interfaceCollection<E>
- Specified by:
add
in interfaceList<E>
- Overrides:
add
in classAbstractSequence<E>
-
add
public void add(int index, E o)
Description copied from class:AbstractSequence
See java.util.List.
-
addPos
protected int addPos(int ipos, E value)
Description copied from class:AbstractSequence
Add a value at a specified Pos.- Overrides:
addPos
in classAbstractSequence<E>
- Returns:
- the updated Pos, which is after the inserted value..
-
addSpace
protected void addSpace(int index, int count)
Insert count unspecified elements at index.
-
delete
public void delete(int start, int end)
-
clearBuffer
protected abstract void clearBuffer(int start, int count)
-
toDataArray
public Object toDataArray()
-
getTag
public String getTag()
This is convenience hack for printing "uniform vectors" (srfi 4). It may go away without notice!
-
writeExternal
public void writeExternal(ObjectOutput out) throws IOException
- Specified by:
writeExternal
in interfaceExternalizable
- Throws:
IOException
-
readExternal
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
- Specified by:
readExternal
in interfaceExternalizable
- Throws:
IOException
ClassNotFoundException
-
-