Package gnu.lists

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, SequencedCollection<E>
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 of get(i) is a Unicode code point, so it is found at offset computed by Character.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:
  • Field Details

  • Constructor Details

    • SimpleVector

      public SimpleVector()
  • Method Details

    • 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 are buffer[offset <: offset+size].
    • isGapBuffer

      protected final boolean isGapBuffer()
      The values are buffer[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.
      Specified by:
      size in interface Collection<E>
      Specified by:
      size in interface List<E>
      Specified by:
      size in interface Sequence<E>
      Overrides:
      size in class AbstractSequence<E>
    • vsize

      protected int vsize()
    • effectiveIndex

      public int effectiveIndex(int index)
      Specified by:
      effectiveIndex in interface Array<E>
      Overrides:
      effectiveIndex in class AbstractSequence<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 class AbstractSequence<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 interface Array<E>
      Overrides:
      asImmutable in class AbstractSequence<E>
    • checkCanWrite

      protected void checkCanWrite()
      Overrides:
      checkCanWrite in class AbstractSequence<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 that get(i) is data[where]; get(i+1) is data[where+1]; until get(i+size-1). The size is at least 1 (unless index==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 class AbstractSequence<E>
    • getBuffer

      protected abstract Object getBuffer()
    • getRowMajor

      public E getRowMajor(int i)
      Specified by:
      getRowMajor in interface Array<E>
      Overrides:
      getRowMajor in class AbstractSequence<E>
    • forEach

      public void forEach(Consumer<? super E> action)
      Specified by:
      forEach in interface Iterable<E>
    • fill

      public void fill(E value)
      Specified by:
      fill in interface Sequence<E>
      Overrides:
      fill in class AbstractSequence<E>
    • 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 interface Collection<E>
      Specified by:
      add in interface List<E>
      Overrides:
      add in class AbstractSequence<E>
    • add

      public void add(int index, E o)
      Description copied from class: AbstractSequence
      See java.util.List.
      Specified by:
      add in interface List<E>
      Overrides:
      add in class AbstractSequence<E>
    • addPos

      protected int addPos(int ipos, E value)
      Description copied from class: AbstractSequence
      Add a value at a specified Pos.
      Overrides:
      addPos in class AbstractSequence<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 interface Externalizable
      Throws:
      IOException
    • readExternal

      public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
      Specified by:
      readExternal in interface Externalizable
      Throws:
      IOException
      ClassNotFoundException