LinkedLists¶
Usage
use LinkedLists;
or
import LinkedLists;
This module provides a simple singly linked list.
Note
This module is expected to change in the future.
- record LinkedList : serializable¶
A singly linked list.
Note
destroy
must be called to reclaim any memory used by the list.- type eltType¶
The type of the data stored in every node.
- var size : int¶
The number of nodes in the list.
- iter these()¶
Iterate over the list, yielding each element.
- Yield type:
eltType
- proc ref append(e: eltType)¶
Append e to the list.
- proc ref push_back(e: eltType)¶
Synonym for append.
- proc ref append(e: eltType, es: eltType ...?k)
Append all of the supplied arguments to the list.
- proc ref prepend(e: eltType)¶
Prepend e to the list.
- proc push_front(e: eltType)¶
Synonym for prepend.
- proc ref concat(l: LinkedList(eltType))¶
Append all the elements in l to the end of the list.
- proc ref remove(x: eltType)¶
Remove the first encountered instance of x from the list. Does nothing if x is not present in the list.
- proc ref pop_front() : eltType¶
Remove the first element from the list and return it. It is an error to call this function on an empty list.
- proc contains(const e: eltType) : bool¶
Returns true if this list contains an element equal to the value of e. Returns false otherwise.
- Arguments:
e – The element search for
- Returns:
true if the e was found
- Return type:
bool
- proc ref first() ref : eltType¶
Returns a reference to the first item in the list
Warning
Calling this method on an empty list will cause the currently running program to halt. If the –fast flag is used, no safety checks will be performed
- Returns:
a reference to the first item in the list
- Return type:
ref eltType
- proc ref last() ref : eltType¶
Returns a reference to the last item in the list
Warning
Calling this method on an empty list will cause the currently running program to halt. If the –fast flag is used, no safety checks will be performed
- Returns:
a reference to the last item in the list
- Return type:
ref eltType
- proc ref destroy()¶
Delete every node in the list.
- proc serialize(writer, ref serializer) throws¶
- proc ref deserialize(reader: fileReader, ref deserializer) throws where reader.deserializerType == IO.defaultDeserializer¶
- proc ref deserialize(reader: fileReader, ref deserializer) throws
- proc makeList(x ...?k)¶
Initialize a new
LinkedList
containing all of the supplied arguments.- Arguments:
x : T – Every argument must be of type T.
- Return type:
LinkedList(T)