A
- the type of elements stored in the listpublic final class PList<A> extends Object implements Iterable<A>
cons(Object, PList)
,
starting from the empty list empty()
. They are immutable
and allow (thread-)safe physical sharing of suffixes.
This implementation allows null
elements, in other
words the type of elements A
can be Nullable
.
Modifier and Type | Method and Description |
---|---|
static <A> PList<A> |
concat(PList<A> l1,
PList<A> l2)
This works in constant stack size.
|
static <A> PList<A> |
cons(A head,
PList<A> tail) |
static <A> PList<A> |
empty() |
boolean |
equals(@Nullable Object o) |
void |
forEach(@Nullable Consumer<? super A> consumer) |
int |
hashCode() |
A |
hd() |
boolean |
isEmpty() |
Iterator<A> |
iterator() |
int |
length() |
static void |
main(String[] args)
Simple tests for
PList |
static <A> PList<A> |
rev(PList<A> l)
This works in constant stack size.
|
static <A> PList<A> |
revAppend(PList<A> l1,
PList<A> l2)
This works in constant stack size.
|
static <A> PList<A> |
singleton(A elt) |
PList<A> |
tl() |
String |
toString() |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
spliterator
public static <A> PList<A> empty()
public static <A> PList<A> cons(A head, PList<A> tail)
head
- tail
- head
in front of tail
public static <A> PList<A> singleton(A elt)
elt
- elt
alonepublic A hd()
NoSuchElementException
- if the list is emptypublic PList<A> tl()
NoSuchElementException
- if the list is emptypublic int length()
public boolean isEmpty()
true
if this list is emptypublic static <A> PList<A> revAppend(PList<A> l1, PList<A> l2)
l1
- l2
- l1
, in reverse order, in front of the
elements of l2
public static <A> PList<A> rev(PList<A> l)
l
- l
public static <A> PList<A> concat(PList<A> l1, PList<A> l2)
l1
- l2
- l1
, in order, in front of the elements of l2