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 longCOPY_ON_WRITEprotected static longGAP_FLAGprotected longinfostatic intMAX_GAP_SIZEprotected static longREAD_ONLY_FLAGprotected static longSHARED_FLAGprotected static longSUBRANGE_FLAGprotected static longVERY_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 voidadd(int index, E o)See java.util.List.booleanadd(E o)See java.util.Collection.protected intaddPos(int ipos, E value)Add a value at a specified Pos.protected voidaddSpace(int index, int count)Insert count unspecified elements at index.SimpleVector<E>asImmutable()protected voidcheckCanWrite()protected abstract voidclearBuffer(int start, int count)abstract voidcopyBuffer(int length)voiddelete(int start, int end)protected voiddoCopyOnWrite(int sz)inteffectiveIndex(int index)voidfill(E value)voidforEach(Consumer<? super E> action)protected voidgapReserve(int where, int needed)protected voidgapReserveGeneric(int where, int needed)protected abstract ObjectgetBuffer()abstract intgetBufferLength()protected intgetGapEnd()protected intgetGapSize()protected intgetGapStart()protected intgetOffsetBits()EgetRowMajor(int i)longgetSegment(int index)Get sub-range of this vector, starting at given index.intgetSegment(int index, int len)intgetSegmentReadOnly(int start, int len)protected intgetSizeBits()StringgetTag()This is convenience hack for printing "uniform vectors" (srfi 4).protected booleanisAfterPos(int ipos)Tests whether the position has the "isAfter" property.protected booleanisGapBuffer()The values arebuffer[0 <: size] ++ buffer[gapEnd <: ], where gapEnd = size + offsetbooleanisReadOnly()protected booleanisSubRange()The values arebuffer[offset <: offset+size].protected booleanisVerySimple()If isSimple(), the values are all the values of the buffer.protected abstract SimpleVectornewInstance(int newSize)voidreadExternal(ObjectInput in)protected abstract voidsetBuffer(Object obj)protected voidsetGapBounds(int gapStart, int gapEnd)protected voidsetGapBounds(int gapStart, int gapEnd, long flags)protected voidsetInfoField(int size, int offset, long flags)voidsetReadOnly()voidshift(int srcStart, int dstStart, int count)intsize()See java.util.List.ObjecttoDataArray()protected intvsize()voidwriteExternal(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:SequenceSee java.util.List.
-
vsize
protected int vsize()
-
effectiveIndex
public int effectiveIndex(int index)
- Specified by:
effectiveIndexin interfaceArray<E>- Overrides:
effectiveIndexin 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:
setBufferin 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:
asImmutablein interfaceArray<E>- Overrides:
asImmutablein classAbstractSequence<E>
-
checkCanWrite
protected void checkCanWrite()
- Overrides:
checkCanWritein 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)|wheresuch thatget(i)isdata[where];get(i+1)isdata[where+1]; untilget(i+size-1). Thesizeis 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:AbstractSequenceTests 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:
isAfterPosin classAbstractSequence<E>
-
getBuffer
protected abstract Object getBuffer()
-
getRowMajor
public E getRowMajor(int i)
- Specified by:
getRowMajorin interfaceArray<E>- Overrides:
getRowMajorin 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:AbstractSequenceSee java.util.Collection.- Specified by:
addin interfaceCollection<E>- Specified by:
addin interfaceList<E>- Overrides:
addin classAbstractSequence<E>
-
add
public void add(int index, E o)Description copied from class:AbstractSequenceSee java.util.List.
-
addPos
protected int addPos(int ipos, E value)Description copied from class:AbstractSequenceAdd a value at a specified Pos.- Overrides:
addPosin 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:
writeExternalin interfaceExternalizable- Throws:
IOException
-
readExternal
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
- Specified by:
readExternalin interfaceExternalizable- Throws:
IOExceptionClassNotFoundException
-
-