gnu.lists
Class SimpleVector

java.lang.Object
  extended by gnu.lists.AbstractSequence
      extended by gnu.lists.SimpleVector
All Implemented Interfaces:
Array, Consumable, Sequence, java.lang.Iterable, java.util.Collection, java.util.List
Direct Known 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, EOF_VALUE, eofValue, FLOAT_VALUE, GROUP_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
SimpleVector()
           
 
Method Summary
 void add(int index, java.lang.Object o)
          See java.util.List.
 boolean add(java.lang.Object o)
          See java.util.Collection.
 boolean addAll(int index, java.util.Collection c)
          See java.util.Collection.
protected  int addPos(int ipos, java.lang.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(int fromIndex, int toIndex, java.lang.Object value)
           
 void fill(java.lang.Object value)
           
 void fillPosRange(int fromPos, int toPos, java.lang.Object value)
           
 java.lang.Object get(int index)
          See java.util.List.
protected abstract  java.lang.Object getBuffer()
           
protected abstract  java.lang.Object getBuffer(int index)
           
abstract  int getBufferLength()
          Get the allocated length of the data buffer.
 int getElementKind()
           
 int getNextKind(int ipos)
           
 java.lang.Object getPosNext(int ipos)
          Get the element following the specified position.
 java.lang.Object getRowMajor(int i)
           
 java.lang.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.
 java.lang.Object remove(int index)
           
 boolean remove(java.lang.Object o)
           
 boolean removeAll(java.util.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(java.util.Collection c)
           
 java.lang.Object set(int index, java.lang.Object value)
           
protected abstract  java.lang.Object setBuffer(int index, java.lang.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
addAll, append, append, append, baseUriOfPos, compare, compare, compare, consume, contains, containsAll, copyPos, createRelativePos, elements, endPos, equals, equals, firstAttributePos, firstChildPos, fromEndIndex, get, getAttribute, getAttributeLength, getContainingSequenceSize, getEffectiveIndex, getIndexDifference, getIterator, getIterator, getIteratorAtPos, getLowBound, getNextTypeName, getNextTypeObject, getPosPrevious, getSize, gotoAttributesStart, gotoChildrenStart, gotoParent, hashCode, hasNext, hasPrevious, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, nextIndex, nextMatching, parentPos, previousPos, rank, releasePos, set, setPosNext, setPosPrevious, stableCompare, startPos, subList, subSequence, subSequencePos, toArray, toArray, toString, toString, unsupported
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface gnu.lists.Sequence
elements, isEmpty
 
Methods inherited from interface java.util.List
addAll, contains, containsAll, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, subList, toArray, toArray
 
Methods inherited from interface gnu.lists.Consumable
consume
 
Methods inherited from interface gnu.lists.Array
get, getEffectiveIndex, getLowBound, getSize, isEmpty, rank, set
 

Field Detail

size

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

Constructor Detail

SimpleVector

public SimpleVector()
Method Detail

size

public final int size()
Description copied from class: AbstractSequence
See java.util.List.

Specified by:
size in interface Sequence
Specified by:
size in interface java.util.Collection
Specified by:
size in interface java.util.List
Specified by:
size in class AbstractSequence

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.


getBufferLength

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


setBufferLength

public abstract void setBufferLength(int length)

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 class AbstractSequence

nextIndex

protected int nextIndex(int ipos)
Description copied from class: AbstractSequence
Get the offset from the beginning corresponding to a position cookie.

Overrides:
nextIndex in class AbstractSequence

createPos

public int createPos(int index,
                     boolean isAfter)
Description copied from class: AbstractSequence
Generate a position at a given index. The result is a position cookie that must be free'd with releasePos.

Specified by:
createPos in class AbstractSequence
Parameters:
index - offset from beginning of desired position
isAfter - should the position have the isAfter property

nextPos

public int nextPos(int ipos)
Description copied from class: AbstractSequence
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 class AbstractSequence

getBuffer

protected abstract java.lang.Object getBuffer()

get

public java.lang.Object get(int index)
Description copied from class: AbstractSequence
See java.util.List.

Specified by:
get in interface Sequence
Specified by:
get in interface java.util.List
Specified by:
get in class AbstractSequence

getPosNext

public java.lang.Object getPosNext(int ipos)
Description copied from class: AbstractSequence
Get the element following the specified position.

Overrides:
getPosNext in class AbstractSequence
Parameters:
ipos - the specified position.
Returns:
the following element, or eofValue if there is none. Called by SeqPosition.getNext.

intAtBuffer

public int intAtBuffer(int index)

intAt

public int intAt(int index)

longAt

public long longAt(int index)

longAtBuffer

public long longAtBuffer(int index)

getRowMajor

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

getBuffer

protected abstract java.lang.Object getBuffer(int index)

set

public java.lang.Object set(int index,
                            java.lang.Object value)
Specified by:
set in interface java.util.List
Overrides:
set in class AbstractSequence

setBuffer

protected abstract java.lang.Object setBuffer(int index,
                                              java.lang.Object value)

fill

public void fill(java.lang.Object value)
Specified by:
fill in interface Sequence
Overrides:
fill in class AbstractSequence

fillPosRange

public void fillPosRange(int fromPos,
                         int toPos,
                         java.lang.Object value)
Overrides:
fillPosRange in class AbstractSequence

fill

public void fill(int fromIndex,
                 int toIndex,
                 java.lang.Object value)
Overrides:
fill in class AbstractSequence

shift

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

add

public boolean add(java.lang.Object o)
Description copied from class: AbstractSequence
See java.util.Collection.

Specified by:
add in interface java.util.Collection
Specified by:
add in interface java.util.List
Overrides:
add in class AbstractSequence

addPos

protected int addPos(int ipos,
                     java.lang.Object value)
Description copied from class: AbstractSequence
Add a value at a specified Pos.

Overrides:
addPos in class AbstractSequence
Returns:
the updated Pos, which is after the inserted value..

add

public void add(int index,
                java.lang.Object o)
Description copied from class: AbstractSequence
See java.util.List.

Specified by:
add in interface java.util.List
Overrides:
add in class AbstractSequence

addAll

public boolean addAll(int index,
                      java.util.Collection c)
Description copied from class: AbstractSequence
See java.util.Collection.

Specified by:
addAll in interface java.util.List
Overrides:
addAll in class AbstractSequence

clearBuffer

protected abstract void clearBuffer(int start,
                                    int count)

removePosRange

protected void removePosRange(int ipos0,
                              int ipos1)
Description copied from class: AbstractSequence
Remove a range where each end-point is a position in a container.

Overrides:
removePosRange in class AbstractSequence
Parameters:
ipos0 - start of range, as a poistion
ipos1 - end of range

removePos

public void removePos(int ipos,
                      int count)
Description copied from class: AbstractSequence
Remove one or more elements.

Overrides:
removePos in class 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).

remove

public java.lang.Object remove(int index)
Specified by:
remove in interface java.util.List
Overrides:
remove in class AbstractSequence

remove

public boolean remove(java.lang.Object o)
Specified by:
remove in interface java.util.Collection
Specified by:
remove in interface java.util.List
Overrides:
remove in class AbstractSequence

removeAll

public boolean removeAll(java.util.Collection c)
Specified by:
removeAll in interface java.util.Collection
Specified by:
removeAll in interface java.util.List
Overrides:
removeAll in class AbstractSequence

retainAll

public boolean retainAll(java.util.Collection c)
Specified by:
retainAll in interface java.util.Collection
Specified by:
retainAll in interface java.util.List
Overrides:
retainAll in class AbstractSequence

clear

public void clear()
Specified by:
clear in interface java.util.Collection
Specified by:
clear in interface java.util.List
Overrides:
clear in class AbstractSequence

getTag

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


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)
Description copied from class: AbstractSequence
Copy an element specified by a position pair to a Consumer.

Overrides:
consumeNext in class AbstractSequence
Returns:
if hasNext(ipos).

consumePosRange

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

getNextKind

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

getElementKind

public int getElementKind()

transpose

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