Class VecInternal

java.lang.Object
org.kink_lang.kink.internal.vec.VecInternal
Direct Known Subclasses:
TraitVecInternal

public abstract class VecInternal extends Object
Container of vec elements.

A vec internal has a fixed capacity, which is greater than or equal to the size. If the size of the result of a linear update method such as insert(int, Val) is bigger than the capacity, the method returns a newly created vec internal, instead of modifying this vec internal.

This class is weakly thread-safe, in the sense that if preconditions hold, actions at least return valid vals, and/or don't break the state of the instance, even if the instance is modified by another thread concurrently.

If a read R in a thread reads a val V from the VecInternal which is written by a write W in another thread, any writes which happen-before W happen before any reads after (in the happens-before order) R.

  • Method Details

    • of

      public static VecInternal of(Vm vm, List<? extends Val> list)
      Returns a new vec internal containing the elements of the list.
      Parameters:
      vm - the vm.
      list - the list of vals.
      Returns:
      a new vec internal containing the elements of the list.
    • of

      public static VecInternal of(Vm vm, Val[] array, int from, int to)
      Returns a new vec containing elements between from (inclusive) and to (exclusive) on the array.
      Parameters:
      vm - the vm.
      array - the array of vals.
      from - the beginning index (inclusive) on the array.
      to - the end index (exclusive) on the array.
      Returns:
      a new vec internal.
    • of

      public static VecInternal of(Vm vm, Val e0)
      Returns a new vec internal.
      Parameters:
      vm - the vm.
      e0 - the #0 elem.
      Returns:
      a new vec internal.
    • of

      public static VecInternal of(Vm vm, Val e0, Val e1)
      Returns a new vec internal.
      Parameters:
      vm - the vm.
      e0 - the #0 elem.
      e1 - the #1 elem.
      Returns:
      a new vec internal.
    • of

      public static VecInternal of(Vm vm, Val e0, Val e1, Val e2)
      Returns a new vec internal.
      Parameters:
      vm - the vm.
      e0 - the #0 elem.
      e1 - the #1 elem.
      e2 - the #2 elem.
      Returns:
      a new vec internal.
    • of

      public static VecInternal of(Vm vm, Val e0, Val e1, Val e2, Val e3)
      Returns a new vec internal.
      Parameters:
      vm - the vm.
      e0 - the #0 elem.
      e1 - the #1 elem.
      e2 - the #2 elem.
      e3 - the #3 elem.
      Returns:
      a new vec internal.
    • ofCapa

      public static VecInternal ofCapa(Vm vm, int capa)
      Returns a new empty vec internal with the specified capa.
      Parameters:
      vm - the vm.
      capa - the capa.
      Returns:
      a new empty vec internal with the specified capa.
    • size

      public int size()
      Returns the size of the vec internal.
      Returns:
      the size of the vec internal.
    • get

      public Val get(int index)
      Returns the indexed element.

      Precondition: 0 <= index < capa.

      Parameters:
      index - the index.
      Returns:
      the indexed element.
    • getTrait

      @Nullable public abstract MaybeTrait getTrait()
      Returns the trait vec internal equal to this if possible; otherwise null.
      Returns:
      the trait vec internal equal to this if possible, or null.
    • append

      @CheckReturnValue public VecInternal append(Val val)
      Inserts a val to the end.

      This is a linear update make.

      Parameters:
      val - the inserted val.
      Returns:
      the result vec internal; it may be this.
    • set

      @CheckReturnValue public abstract VecInternal set(int index, Val val)
      Sets the indexed element.

      This is a linear update make.

      Parameters:
      index - the index.
      val - the element val.
      Returns:
      this.
    • remove

      @CheckReturnValue public abstract VecInternal remove(int index)
      Removes the indexed element from the vec internal.

      This is a linear update make.

      Precondition: 0 <= index < capa.

      Parameters:
      index - the index.
      Returns:
      this.
    • removeRange

      @CheckReturnValue public abstract VecInternal removeRange(int from, int to)
      Removes the range between the indices from the vec internal.

      This is a linear update make.

      Precondition: 0 <= from <= to <= capa.

      Parameters:
      from - the beginning index of the range (inclusive).
      to - the end index of the range (exclusive).
      Returns:
      this.
    • insert

      @CheckReturnValue public abstract VecInternal insert(int index, Val val)
      Inserts a val to the position index.

      This is a linear update make.

      Precondition: 0 <= index <= capa.

      Parameters:
      index - the position index.
      val - the inserted val.
      Returns:
      the result vec internal; it may be this.
    • insertAll

      @CheckReturnValue public abstract VecInternal insertAll(int index, VecInternal added)
      Inserts the elements of added to the position index.

      This is a linear update make.

      Precondition: 0 <= index <= capa.

      Parameters:
      index - the position index.
      added - the added vec internal.
      Returns:
      the result vec internal; it may be this.
    • insertRange

      @CheckReturnValue public abstract VecInternal insertRange(int index, Val[] src, int from, int to)
      Inserts the elements in the range of src to the position index.

      This is a linear update make.

      Precondition: 0 <= index <= capa, 0 <= from <= to < src.length.

      Parameters:
      index - the position index.
      src - array containing the added vals.
      from - the from index of the src.
      to - the to index of the src.
      Returns:
      the result vec internal; it may be this.
    • copyRangeWithCapa

      public VecInternal copyRangeWithCapa(int from, int to, int newCapa)
      Returns a new vec internal copied from the range of this vec internal.

      The capacity of the result vec internal is set to newCapa.

      Precondition: 0 <= from <= to <= capa.

      Parameters:
      from - the beginning index of the range (inclusive).
      to - the end index of the range (exclusive).
      newCapa - the capacity of the new vec internal.
      Returns:
      a new vec internal.
    • copyRange

      public VecInternal copyRange(int from, int to)
      Returns a new vec internal copied from the range of this vec internal.

      The capacity of the result vec internal is set to to - from.

      Precondition: 0 <= from <= to <= capa.

      Parameters:
      from - the beginning index of the range (inclusive).
      to - the end index of the range (exclusive).
      Returns:
      a new vec internal.
    • copy

      public VecInternal copy()
      Returns the new vec internal copying the whole elements of this vec internal.

      The capacity of the result vec internal is set to the initial size.

      Returns:
      a new vec internal.
    • copyTo

      public void copyTo(Val[] dest, int destIndex, int size)
      Copies the vals between [0] to [size - 1] to the dest array.
      Parameters:
      dest - the dest array.
      destIndex - the index of the dest array to which the vals are copied.
      size - the size of the range of the vals.
    • capa

      public int capa()
      Returns the capacity of the vec internal.
      Returns:
      the capacity of the vec internal.
    • asList

      public List<Val> asList()
      Returns a list which is a view of the vec internal.
      Returns:
      a list which is a view of the vec internal.