Class TreePVector<E>

Type Parameters:
E -
All Implemented Interfaces:
Serializable, Iterable<E>, Collection<E>, List<E>, PCollection<E>, PSequence<E>, PVector<E>

public class TreePVector<E> extends AbstractUnmodifiableList<E> implements PVector<E>, 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:
  • Field Details

  • Constructor Details

  • Method Details

    • 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(Collection<? extends E> list)
      Type Parameters:
      E -
      Parameters:
      list -
      Returns:
      empty().plusAll(list)
    • size

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

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

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

      public TreePVector<E> subList(int start, int end)
      Specified by:
      subList in interface List<E>
      Specified by:
      subList in interface PSequence<E>
      Specified by:
      subList in interface PVector<E>
      Overrides:
      subList in class 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>
      Parameters:
      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>
      Parameters:
      i -
      e -
      Returns:
      a sequence consisting of the elements of this with e inserted at index i.
    • minus

      public TreePVector<E> minus(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>
      Parameters:
      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>
      Parameters:
      i -
      Returns:
      a sequence consisting of the elements of this with the element at index i removed.
    • plusAll

      public TreePVector<E> plusAll(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>
      Parameters:
      list -
      Returns:
      a collection which contains all of the elements of list and this
    • minusAll

      public TreePVector<E> minusAll(Collection<?> list)
      Specified by:
      minusAll in interface PCollection<E>
      Specified by:
      minusAll in interface PSequence<E>
      Specified by:
      minusAll in interface PVector<E>
      Parameters:
      list -
      Returns:
      this with all elements of list completely removed
    • plusAll

      public TreePVector<E> plusAll(int i, Collection<? extends E> list)
      Specified by:
      plusAll in interface PSequence<E>
      Specified by:
      plusAll in interface PVector<E>
      Parameters:
      i -
      list -
      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>
      Parameters:
      i -
      e -
      Returns:
      a sequence consisting of the elements of this with e replacing the element at index i.