| java.lang.Object gnu.lists.SeqPosition gnu.lists.ExtPosition gnu.lists.LListPosition
LListPosition | class LListPosition extends ExtPosition (Code) | | LListPosition - a SeqPosition for LLists.
Normally, we just use an int pos to indicate a position in a
sequence. But for linked lists that would be very inefficient.
So this sub-class in addition uses an xpos field to point to the
current Pair. However, we do so in a non-obvious way. After a next(),
xpos points to *two* Pairs before the logical iterator position
(the cursor). This is because of the requirement for remove(),
which needs to be able to remove the element *before* the cursor.
But to unlink that element, we need to change the 'next' field
of the Pair before that again.
However, after a call to 'previous', we cannot cheaply move the
xpos pointer backwards, so we leave it as is. Therefore, we
get the rule that when isAfter() is false the cursor position is
after the Pair pointed by xpos; when isAfter() is true then
the cursor position is after the Pair ((Pair) xpos).cdr).
If the cursor position is too early in the list to satisfy this
invariant, then xpos==null.
|
LListPosition | public LListPosition(LList seq, int index, boolean isAfter)(Code) | | |
getNextPair | public Pair getNextPair()(Code) | | Get the Pair whose car contains the next element, or null.
|
getPreviousPair | public Pair getPreviousPair()(Code) | | Get the Pair whose car contains the previous element, or null.
|
gotoNext | public boolean gotoNext()(Code) | | |
gotoPrevious | public boolean gotoPrevious()(Code) | | |
hasNext | public boolean hasNext()(Code) | | |
hasPrevious | public boolean hasPrevious()(Code) | | |
nextIndex | public int nextIndex()(Code) | | |
set | public void set(LList seq, int index, boolean isAfter)(Code) | | |
|
|