Package gnu.lists

Class 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 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:
    Serialized Form
    • Constructor Detail

      • SimpleVector

        public SimpleVector()
    • 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 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()
      • vsize

        protected int vsize()
      • gapReserve

        protected void gapReserve​(int where,
                                  int needed)
      • gapReserveGeneric

        protected final void gapReserveGeneric​(int where,
                                               int needed)
      • getBufferLength

        public abstract int getBufferLength()
      • copyBuffer

        public abstract void copyBuffer​(int length)
      • newInstance

        protected abstract SimpleVector newInstance​(int newSize)
      • 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()
      • shift

        public void shift​(int srcStart,
                          int dstStart,
                          int count)
      • 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!