Class TreePVector<E>

  • Type Parameters:
    E -
    All Implemented Interfaces:
    java.io.Serializable, java.lang.Iterable<E>, java.util.Collection<E>, java.util.List<E>, PCollection<E>, PSequence<E>, PVector<E>

    public class TreePVector<E>
    extends AbstractUnmodifiableList<E>
    implements PVector<E>, java.io.Serializable
    A persistent vector of elements.

    This implementation is backed by an IntTreePMap and supports logarithmic-time querying, setting, insertion, and removal.

    This implementation is thread-safe (assuming Java's AbstractList is thread-safe) although its iterators may not be.

    Null values are supported.

    See Also:
    Serialized Form
    • Constructor Detail

    • Method Detail

      • empty

        public static <E> TreePVector<E> empty()
        Type Parameters:
        E -
        Returns:
        an empty vector
      • singleton

        public static <E> TreePVector<E> singleton​(E e)
        Type Parameters:
        E -
        Parameters:
        e -
        Returns:
        empty().plus(e)
      • from

        public static <E> TreePVector<E> from​(java.util.Collection<? extends E> list)
        Type Parameters:
        E -
        Parameters:
        list -
        Returns:
        empty().plusAll(list)
      • size

        public int size()
        Specified by:
        size in interface java.util.Collection<E>
        Specified by:
        size in interface java.util.List<E>
        Specified by:
        size in class java.util.AbstractCollection<E>
      • get

        public E get​(int index)
        Specified by:
        get in interface java.util.List<E>
        Specified by:
        get in class java.util.AbstractList<E>
      • iterator

        public java.util.Iterator<E> iterator()
        Specified by:
        iterator in interface java.util.Collection<E>
        Specified by:
        iterator in interface java.lang.Iterable<E>
        Specified by:
        iterator in interface java.util.List<E>
        Overrides:
        iterator in class java.util.AbstractList<E>
      • subList

        public TreePVector<E> subList​(int start,
                                      int end)
        Specified by:
        subList in interface java.util.List<E>
        Specified by:
        subList in interface PSequence<E>
        Specified by:
        subList in interface PVector<E>
        Overrides:
        subList in class java.util.AbstractList<E>
      • plus

        public TreePVector<E> plus​(E e)
        Description copied from interface: PVector
        Returns a vector consisting of the elements of this with e appended.
        Specified by:
        plus in interface PCollection<E>
        Specified by:
        plus in interface PSequence<E>
        Specified by:
        plus in interface PVector<E>
        Returns:
        a collection which contains e and all of the elements of this
      • plus

        public TreePVector<E> plus​(int i,
                                   E e)
        Specified by:
        plus in interface PSequence<E>
        Specified by:
        plus in interface PVector<E>
        Returns:
        a sequence consisting of the elements of this with e inserted at index i.
      • minus

        public TreePVector<E> minus​(java.lang.Object e)
        Description copied from interface: PSequence
        Returns a sequence consisting of the elements of this without the first occurrence of e.
        Specified by:
        minus in interface PCollection<E>
        Specified by:
        minus in interface PSequence<E>
        Specified by:
        minus in interface PVector<E>
        Returns:
        this with a single instance of e removed, if e is in this
      • minus

        public TreePVector<E> minus​(int i)
        Specified by:
        minus in interface PSequence<E>
        Specified by:
        minus in interface PVector<E>
        Returns:
        a sequence consisting of the elements of this with the element at index i removed.
      • plusAll

        public TreePVector<E> plusAll​(java.util.Collection<? extends E> list)
        Description copied from interface: PVector
        Returns a vector consisting of the elements of this with list appended.
        Specified by:
        plusAll in interface PCollection<E>
        Specified by:
        plusAll in interface PSequence<E>
        Specified by:
        plusAll in interface PVector<E>
        Returns:
        a collection which contains all of the elements of list and this
      • plusAll

        public TreePVector<E> plusAll​(int i,
                                      java.util.Collection<? extends E> list)
        Specified by:
        plusAll in interface PSequence<E>
        Specified by:
        plusAll in interface PVector<E>
        Returns:
        a sequence consisting of the elements of this with list inserted at index i.
      • with

        public PVector<E> with​(int i,
                               E e)
        Specified by:
        with in interface PSequence<E>
        Specified by:
        with in interface PVector<E>
        Returns:
        a sequence consisting of the elements of this with e replacing the element at index i.