- Direct Known Subclasses:
TraitVecInternal
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 Summary
Modifier and TypeMethodDescriptionInserts a val to the end.asList()
Returns a list which is a view of the vec internal.int
capa()
Returns the capacity of the vec internal.copy()
Returns the new vec internal copying the whole elements ofthis
vec internal.copyRange
(int from, int to) Returns a new vec internal copied from the range ofthis
vec internal.copyRangeWithCapa
(int from, int to, int newCapa) Returns a new vec internal copied from the range ofthis
vec internal.void
Copies the vals between [0] to [size - 1] to the dest array.get
(int index) Returns the indexed element.abstract MaybeTrait
getTrait()
Returns the trait vec internal equal tothis
if possible; otherwise null.abstract VecInternal
Inserts a val to the position index.abstract VecInternal
insertAll
(int index, VecInternal added) Inserts the elements ofadded
to the position index.abstract VecInternal
insertRange
(int index, Val[] src, int from, int to) Inserts the elements in the range ofsrc
to the position index.static VecInternal
Returns a new vec internal containing the elements of the list.static VecInternal
Returns a new vec internal.static VecInternal
Returns a new vec containing elements betweenfrom
(inclusive) andto
(exclusive) on the array.static VecInternal
Returns a new vec internal.static VecInternal
Returns a new vec internal.static VecInternal
Returns a new vec internal.static VecInternal
Returns a new empty vec internal with the specified capa.abstract VecInternal
remove
(int index) Removes the indexed element from the vec internal.abstract VecInternal
removeRange
(int from, int to) Removes the range between the indices from the vec internal.abstract VecInternal
Sets the indexed element.int
size()
Returns the size of the vec internal.
-
Method Details
-
of
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
Returns a new vec containing elements betweenfrom
(inclusive) andto
(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
Returns a new vec internal.- Parameters:
vm
- the vm.e0
- the #0 elem.- Returns:
- a new vec internal.
-
of
Returns a new vec internal.- Parameters:
vm
- the vm.e0
- the #0 elem.e1
- the #1 elem.- Returns:
- a new vec internal.
-
of
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
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
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
Returns the indexed element.Precondition: 0 <= index < capa.
- Parameters:
index
- the index.- Returns:
- the indexed element.
-
getTrait
Returns the trait vec internal equal tothis
if possible; otherwise null.- Returns:
- the trait vec internal equal to
this
if possible, or null.
-
append
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
Sets the indexed element.This is a linear update make.
- Parameters:
index
- the index.val
- the element val.- Returns:
- this.
-
remove
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
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
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
Inserts the elements ofadded
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
Inserts the elements in the range ofsrc
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
Returns a new vec internal copied from the range ofthis
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
Returns a new vec internal copied from the range ofthis
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
Returns the new vec internal copying the whole elements ofthis
vec internal.The capacity of the result vec internal is set to the initial size.
- Returns:
- a new vec internal.
-
copyTo
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
Returns a list which is a view of the vec internal.- Returns:
- a list which is a view of the vec internal.
-