Class LinearList<V>
java.lang.Object
io.lacuna.bifurcan.IList.Mixin<V>
io.lacuna.bifurcan.LinearList<V>
- All Implemented Interfaces:
ICollection<IList<V>,
,V> IList<V>
,Cloneable
,Iterable<V>
A simple implementation of a mutable list combining the best characteristics of
ArrayList
and
ArrayDeque
, allowing elements to be added and removed from both ends of the collection and
allowing random-access reads and updates. Unlike List
, it can only hold Integer.MAX_VALUE
elements.
Calls to IList.concat(IList)
, IList.slice(long, long)
, and IList.split(int)
create virtual collections which
retain a reference to the whole underlying collection, and are somewhat less efficient than LinearList
.
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.lacuna.bifurcan.IList
IList.Mixin<V>
-
Field Summary
Fields inherited from class io.lacuna.bifurcan.IList.Mixin
hash
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionclear()
clone()
forked()
This returns a data structure which is forked, which is equivalent to Clojure's persistent data structures, also sometimes called functional or immutable.static <V> LinearList
<V> static <V> LinearList
<V> static <V> LinearList
<V> from
(Collection<V> collection) static <V> LinearList
<V> boolean
isLinear()
iterator()
linear()
This returns a data structure which is linear, or temporarily mutable.nth
(long idx) static <V> LinearList
<V> of
(V... elements) popFirst()
Removes, and returns, the first element of the list.popLast()
Removes, and returns, the last element of the list.long
size()
Methods inherited from class io.lacuna.bifurcan.IList.Mixin
equals, hashCode, toString
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface io.lacuna.bifurcan.ICollection
nth
-
Constructor Details
-
LinearList
public LinearList() -
LinearList
public LinearList(int capacity) - Parameters:
capacity
- the initial capacity of the list
-
-
Method Details
-
of
-
from
- Returns:
- a list containing the entries of
collection
-
from
- Returns:
- a list containing the elements of
iterable
-
from
- Returns:
- a list containing all remaining elements of
iterator
-
from
- Returns:
- a list containing the elements of
list
-
isLinear
-
addLast
-
addFirst
-
removeFirst
- Specified by:
removeFirst
in interfaceIList<V>
- Returns:
- a new list with the first value removed, or the same value if already empty
-
removeLast
- Specified by:
removeLast
in interfaceIList<V>
- Returns:
- a new list with the last value removed, or the same list if already empty
-
clear
-
set
- Specified by:
set
in interfaceIList<V>
- Returns:
- a new list, with the element at
idx
overwritten withvalue
. Ifidx
is equal toICollection.size()
, the value is appended.
-
nth
-
popFirst
Removes, and returns, the first element of the list.- Returns:
- the first element of the list
- Throws:
IndexOutOfBoundsException
- if the list is empty
-
popLast
Removes, and returns, the last element of the list.- Returns:
- the last element of the list
- Throws:
IndexOutOfBoundsException
- if the list is empty
-
iterator
-
size
public long size()- Specified by:
size
in interfaceICollection<IList<V>,
V> - Returns:
- the number of elements in the collection
-
forked
Description copied from interface:ICollection
This returns a data structure which is forked, which is equivalent to Clojure's persistent data structures, also sometimes called functional or immutable. This is called "forked" because it means that multiple functions can make divergent changes to the data structure without affecting each other.If only a single function or scope uses the data structure, it can be left as a linear data structure, which can have significant performance benefits.
If the data structure is already forked, it will simply return itself.
-
linear
Description copied from interface:ICollection
This returns a data structure which is linear, or temporarily mutable. The term "linear", as used here, does not completely align with the formal definition of linear types as used in type theory. It is meant to describe the linear dataflow of the method calls, and as a converse to "forked" data structures.If
ICollection.forked()
is called on a linear collection, all references to that linear collection should be discarded.If the data structure is already linear, it will simply return itself.
-
clone
- Specified by:
clone
in interfaceICollection<IList<V>,
V> - Overrides:
clone
in classIList.Mixin<V>
- Returns:
- a cloned copy of the collection
-