gnu.lists

Class SimpleVector

Implemented Interfaces:
java.util.List, Array, Consumable, Sequence
Known Direct Subclasses:
BitVector, F32Vector, F64Vector, FString, FVector, S16Vector, S32Vector, S64Vector, S8Vector, U16Vector, U32Vector, U64Vector, U8Vector

public abstract class SimpleVector
extends AbstractSequence
implements Sequence, Array

A SimpleVector implement as a simple array plus a current size. Methods with the word "Buffer" are methods which use the underlying array, ignoring the 'size' field. Can be used to implement CommonLisp simple vectors, but all simple vectors are also adjustable (by re-allocating the buffer) and have a fill pointer (the size field).

Field Summary

int
size
The (current) number of elements.

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, 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, eofValue

Method Summary

boolean
add(Object o)
See java.util.Collection.
void
add(int index, Object o)
See java.util.List.
boolean
addAll(int index, Collection c)
See java.util.Collection.
protected int
addPos(int ipos, Object value)
Add a value at a specified Pos.
void
clear()
protected abstract void
clearBuffer(int start, int count)
protected static int
compareToInt(SimpleVector v1, SimpleVector v2)
protected static int
compareToLong(SimpleVector v1, SimpleVector v2)
void
consume(int start, int length, Consumer out)
boolean
consumeNext(int ipos, Consumer out)
Copy an element specified by a position pair to a Consumer.
void
consumePosRange(int iposStart, int iposEnd, Consumer out)
int
createPos(int index, boolean isAfter)
Generate a position at a given index.
void
fill(Object value)
void
fill(int fromIndex, int toIndex, Object value)
void
fillPosRange(int fromPos, int toPos, Object value)
Object
get(int index)
See java.util.List.
protected abstract Object
getBuffer()
protected abstract Object
getBuffer(int index)
abstract int
getBufferLength()
Get the allocated length of the data buffer.
int
getElementKind()
int
getNextKind(int ipos)
Object
getPosNext(int ipos)
Get the element following the specified position.
Object
getRowMajor(int i)
String
getTag()
This is convenience hack for printing "uniform vectors" (srfi 4).
int
intAt(int index)
int
intAtBuffer(int index)
protected boolean
isAfterPos(int ipos)
Tests whether the position has the "isAfter" property.
long
longAt(int index)
long
longAtBuffer(int index)
protected int
nextIndex(int ipos)
Get the offset from the beginning corresponding to a position cookie.
int
nextPos(int ipos)
Return the next position following the argument.
boolean
remove(Object o)
Object
remove(int index)
boolean
removeAll(Collection c)
void
removePos(int ipos, int count)
Remove one or more elements.
protected void
removePosRange(int ipos0, int ipos1)
Remove a range where each end-point is a position in a container.
boolean
retainAll(Collection c)
Object
set(int index, Object value)
protected abstract Object
setBuffer(int index, Object value)
abstract void
setBufferLength(int length)
void
setSize(int size)
Set the size to a specified value.
void
shift(int srcStart, int dstStart, int count)
int
size()
See java.util.List.
Array
transpose(int[] lowBounds, int[] dimensions, int offset0, int[] factors)

Methods inherited from class gnu.lists.AbstractSequence

add, add, addAll, addAll, addPos, clear, compare, compare, compare, consume, consumeNext, consumePosRange, contains, containsAll, copyPos, createPos, createRelativePos, elements, endPos, equals, equals, fill, fill, fillPosRange, firstAttributePos, firstChildPos, firstChildPos, fromEndIndex, get, get, getAttribute, getAttributeLength, getContainingSequenceSize, getEffectiveIndex, getIndexDifference, getIterator, getIterator, getIteratorAtPos, getLowBound, getNextKind, getNextTypeName, getNextTypeObject, getPosNext, getPosPrevious, getSize, gotoAttributesStart, gotoChildrenStart, gotoParent, hasNext, hasPrevious, hashCode, indexOf, isAfterPos, isEmpty, iterator, lastIndexOf, listIterator, listIterator, nextIndex, nextIndex, nextMatching, nextPos, parentPos, previousPos, rank, releasePos, remove, remove, removeAll, removePos, removePosRange, retainAll, set, set, setPosNext, setPosPrevious, size, stableCompare, startPos, subList, subSequence, subSequencePos, toArray, toArray, toString, toString, unsupported, unsupportedException

Field Details

size

public int size
The (current) number of elements. Must always have size() >= 0 && size() <= getBufferLength().

Method Details

add

public boolean add(Object o)
See java.util.Collection.
Overrides:
add in interface AbstractSequence

add

public void add(int index,
                Object o)
See java.util.List.
Overrides:
add in interface AbstractSequence

addAll

public boolean addAll(int index,
                      Collection c)
See java.util.Collection.
Overrides:
addAll in interface AbstractSequence

addPos

protected int addPos(int ipos,
                     Object value)
Add a value at a specified Pos.
Overrides:
addPos in interface AbstractSequence
Returns:
the updated Pos, which is after the inserted value..

clear

public void clear()
Overrides:
clear in interface AbstractSequence

clearBuffer

protected abstract void clearBuffer(int start,
                                    int count)

compareToInt

protected static int compareToInt(SimpleVector v1,
                                  SimpleVector v2)

compareToLong

protected static int compareToLong(SimpleVector v1,
                                   SimpleVector v2)

consume

public void consume(int start,
                    int length,
                    Consumer out)

consumeNext

public boolean consumeNext(int ipos,
                           Consumer out)
Copy an element specified by a position pair to a Consumer.
Overrides:
consumeNext in interface AbstractSequence
Returns:
if hasNext(ipos).

consumePosRange

public void consumePosRange(int iposStart,
                            int iposEnd,
                            Consumer out)
Overrides:
consumePosRange in interface AbstractSequence

createPos

public int createPos(int index,
                     boolean isAfter)
Generate a position at a given index. The result is a position cookie that must be free'd with releasePos.
Overrides:
createPos in interface AbstractSequence
Parameters:
index - offset from beginning of desired position
isAfter - should the position have the isAfter property

fill

public void fill(Object value)
Specified by:
fill in interface Sequence
Overrides:
fill in interface AbstractSequence

fill

public void fill(int fromIndex,
                 int toIndex,
                 Object value)
Overrides:
fill in interface AbstractSequence

fillPosRange

public void fillPosRange(int fromPos,
                         int toPos,
                         Object value)
Overrides:
fillPosRange in interface AbstractSequence

get

public Object get(int index)
See java.util.List.
Specified by:
get in interface Sequence
Overrides:
get in interface AbstractSequence

getBuffer

protected abstract Object getBuffer()

getBuffer

protected abstract Object getBuffer(int index)

getBufferLength

public abstract int getBufferLength()
Get the allocated length of the data buffer.

getElementKind

public int getElementKind()

getNextKind

public int getNextKind(int ipos)
Overrides:
getNextKind in interface AbstractSequence

getPosNext

public Object getPosNext(int ipos)
Get the element following the specified position.
Overrides:
getPosNext in interface AbstractSequence
Parameters:
ipos - the specified position.
Returns:
the following element, or eofValue if there is none. Called by SeqPosition.getNext.

getRowMajor

public Object getRowMajor(int i)
Specified by:
getRowMajor in interface Array

getTag

public String getTag()
This is convenience hack for printing "uniform vectors" (srfi 4). It may go away without notice!

intAt

public int intAt(int index)

intAtBuffer

public int intAtBuffer(int index)

isAfterPos

protected boolean isAfterPos(int ipos)
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 interface AbstractSequence

longAt

public long longAt(int index)

longAtBuffer

public long longAtBuffer(int index)

nextIndex

protected int nextIndex(int ipos)
Get the offset from the beginning corresponding to a position cookie.
Overrides:
nextIndex in interface AbstractSequence

nextPos

public int nextPos(int ipos)
Return the next position following the argument. The new position has the isAfter property. The argument is implicitly released (as in releasePos). Returns 0 if we are already at end of file.
Overrides:
nextPos in interface AbstractSequence

remove

public boolean remove(Object o)
Overrides:
remove in interface AbstractSequence

remove

public Object remove(int index)
Overrides:
remove in interface AbstractSequence

removeAll

public boolean removeAll(Collection c)
Overrides:
removeAll in interface AbstractSequence

removePos

public void removePos(int ipos,
                      int count)
Remove one or more elements.
Overrides:
removePos in interface AbstractSequence
Parameters:
ipos - position where elements should be removed
count - if non-negative, remove that number of elements following (poses, posNumber); if negative the negative of the number of elements to remove before (poses, posNumber).

removePosRange

protected void removePosRange(int ipos0,
                              int ipos1)
Remove a range where each end-point is a position in a container.
Overrides:
removePosRange in interface AbstractSequence
Parameters:
ipos0 - start of range, as a poistion
ipos1 - end of range

retainAll

public boolean retainAll(Collection c)
Overrides:
retainAll in interface AbstractSequence

set

public Object set(int index,
                  Object value)
Specified by:
set in interface Sequence
Overrides:
set in interface AbstractSequence

setBuffer

protected abstract Object setBuffer(int index,
                                    Object value)

setBufferLength

public abstract void setBufferLength(int length)

setSize

public void setSize(int size)
Set the size to a specified value. The data buffer is grown if needed, with new elements set to zero/null. If size is less than the current value, removed values are set to zero/null.. (This is because if you decrease and then increase the vector the should be zero/null, and it is cleaner and better for gc to do the zeroing/nulling on remove rather than add.) If you need to change the size without setting removed elements to zero/null (e.g. to change Common Lisp's fill pointer) set size directly.

shift

public void shift(int srcStart,
                  int dstStart,
                  int count)

size

public final int size()
See java.util.List.
Specified by:
size in interface Sequence
Overrides:
size in interface AbstractSequence

transpose

public Array transpose(int[] lowBounds,
                       int[] dimensions,
                       int offset0,
                       int[] factors)
Specified by:
transpose in interface Array