hwtest.mlist
Type members
Classlikes
A "header" node for MList
s.
A "header" node for MList
s.
The info
field stores information about the list, such as its length.
The front
field stores a pointer to the front of the list. Maintaining
this pointer in a header node helps avoid a very common bug where the
front of the list changes (either a new list node was added or the front
node was removed) but a pointer elsewhere in the code still points
to the old front. With header nodes, only pointers to the header should
be shared, and every operation that changes the front of the list
should update the header.
- Companion:
- object
A class of singly-linked mutable lists of integers.
A class of singly-linked mutable lists of integers.
MList
is very similar to hwtest.slist.SList, but
with the following differences:
head_=
andtail_=
method supporting assignment to the head and tail of a node.==
and hashing based on pointers rather than the contents of a node.- numerous complications related to the possibility
that an
MList
could contain a cycle.
Here's how the MList
s handle cycles:
- A cyclic list will be displayed as (for example)
MList(1, 2, *3, 4->*)
which indicates that the tail field of the 4 node points back to the 3 node. 2. Two cyclic lists are considered equivalent only if they have EXACTLY the same shape. For example, the following lists are arguably equivalent (because they all consist of a 1 followed by an infinite number of 2s) but are NOT considered equivalent by this package:
MList(1, *2->*)
MList(1, 2, *2->*)
MList(1, *2, 2->*)
- To write tests involving cyclic lists, use the format
(1 *2 3)
where the `*` indicates the beginning of the cycle.
The `*` must be followed by at least one element.
Whitespace is allowed between the `*` and the following
element.
- Companion:
- object