endrov.util.collection
Class PersistentSLinkedList<E>

java.lang.Object
  extended by endrov.util.collection.PersistentSLinkedList<E>

public class PersistentSLinkedList<E>
extends java.lang.Object

Persistent singly linked list. Persistent means that the list is never modified. This only holds true for the list itself; the elements it points to can be modified by the user. The empty list is the value null.


Field Summary
 PersistentSLinkedList<E> next
           
 
Constructor Summary
PersistentSLinkedList(E e)
          Construct list with single element O(1)
PersistentSLinkedList(E a, PersistentSLinkedList<E> next)
          Construct a:b O(1)
 
Method Summary
static
<E> PersistentSLinkedList<E>
cons(E a, PersistentSLinkedList<E> b)
          Construct a:b O(1)
 E head()
          Return the first element O(1)
 java.util.Iterator<E> iterator()
          Iterate over list.
static
<E> int
size(PersistentSLinkedList<E> node)
          Number of elements O(n)
 PersistentSLinkedList<E> tail()
          Return list of following elements O(1)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

next

public PersistentSLinkedList<E> next
Constructor Detail

PersistentSLinkedList

public PersistentSLinkedList(E e)
Construct list with single element O(1)


PersistentSLinkedList

public PersistentSLinkedList(E a,
                             PersistentSLinkedList<E> next)
Construct a:b O(1)

Method Detail

size

public static <E> int size(PersistentSLinkedList<E> node)
Number of elements O(n)


head

public E head()
Return the first element O(1)


tail

public PersistentSLinkedList<E> tail()
Return list of following elements O(1)


cons

public static <E> PersistentSLinkedList<E> cons(E a,
                                                PersistentSLinkedList<E> b)
Construct a:b O(1)


iterator

public java.util.Iterator<E> iterator()
Iterate over list. Creating iterator is O(1)