Package gnu.lists
Class LList
- All Implemented Interfaces:
BoundedHashable
,Consumable
,Sequence<Object>
,Externalizable
,Serializable
,Comparable
,Iterable<Object>
,Collection<Object>
,List<Object>
,SequencedCollection<Object>
public class LList
extends ExtSequence<Object>
implements Sequence<Object>, Externalizable, Comparable
Semi-abstract class for traditions Lisp-style lists.
A list is implemented as a chain of Pair objects, where the
'car' field of the Pair points to a data element, and the 'cdr'
field points to the next Pair. (The names 'car' and 'cdr' are
historical; they refer to hardware on machines form the 60's.)
Includes singleton static Empty, and the Pair sub-class.
- See Also:
-
Field Summary
FieldsFields inherited from class gnu.lists.AbstractSequence
noInts
Fields inherited from interface gnu.lists.Sequence
ATTRIBUTE_VALUE, BOOLEAN_VALUE, CDATA_VALUE, CHAR_VALUE, COMMENT_VALUE, DOCUMENT_VALUE, DOUBLE_VALUE, ELEMENT_VALUE, EOF_VALUE, eofValue, FLOAT_VALUE, INT_S16_VALUE, INT_S32_VALUE, INT_S64_VALUE, INT_S8_VALUE, INT_U16_VALUE, INT_U32_VALUE, INT_U64_VALUE, INT_U8_VALUE, OBJECT_VALUE, PRIM_VALUE, PROCESSING_INSTRUCTION_VALUE, TEXT_BYTE_VALUE
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
boundedHash
(int seed, int limit) Calculate a hash code for this object.static Pair
Utility function used by compiler when inlining `list'.static Pair
Utility function used by compiler when inlining `list'.static Object
checkNonList
(Object rest) Helper to protect against pathological LLists (neithr Pair nor Empty).int
void
static Object
SRFI-1's cons* and Common Lisp's list* function.int
createPos
(int index, boolean isAfter) Generate a position at a given index.int
createRelativePos
(int pos, int delta, boolean isAfter) boolean
get
(int index) See java.util.List.getIterator
(int index) getPosNext
(int ipos) Get the element following the specified position.getPosPrevious
(int ipos) Get the element before the specified position.int
hashCode()
boolean
hasNext
(int ipos) boolean
isEmpty()
True is this sequence contains no elements.static final int
static Pair
static Pair
static Pair
static Pair
static int
listLength
(Object obj, boolean allowOtherSequence) A safe function to count the length of a list.static LList
static LList
static LList
int
nextPos
(int ipos) Return the next position following the argument.void
static LList
reverseInPlace
(Object list) Reverse a list in place, by modifying the cdr fields.protected void
setPosNext
(int ipos, Object value) protected void
setPosPrevious
(int ipos, Object value) int
size()
See java.util.List.toString()
void
Methods inherited from class gnu.lists.ExtSequence
copyPos, isAfterPos, nextIndex, releasePos
Methods inherited from class gnu.lists.AbstractSequence
add, add, addAll, addAll, addPos, asImmutable, badRank, checkCanWrite, checkRank, clear, compare, compare, compare, consume, consumeNext, consumePosRange, contains, containsAll, effectiveIndex, effectiveIndex, effectiveIndex, effectiveIndex, effectiveIndex, elements, endPos, equals, fill, fill, fillPosRange, firstAttributePos, firstChildPos, firstChildPos, fromEndIndex, get, get, get, get, getAttribute, getAttributeLength, getBooleanRaw, getByteRaw, getCharRaw, getContainingSequenceSize, getDoubleRaw, getElementKind, getFloatRaw, getIndexDifference, getInt, getInt, getInt, getInt, getInt, getIntRaw, getIterator, getIteratorAtPos, getLongRaw, getLowBound, getNextKind, getNextTypeName, getNextTypeObject, getRaw, getRowMajor, getShortRaw, getSize, getSize, gotoAttributesStart, gotoChildrenStart, gotoParent, hasPrevious, indexOf, iterator, lastIndexOf, listIterator, listIterator, nextIndex, nextMatching, parentPos, previousPos, rank, remove, remove, removeAll, removePos, removePosRange, retainAll, set, set, setAt, setBuffer, setRaw, stableCompare, startPos, subList, subSequence, subSequencePos, toArray, toArray, toString, unsupported, unsupportedException
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
Methods inherited from interface java.util.List
add, add, addAll, addAll, addFirst, addLast, clear, contains, containsAll, getFirst, getLast, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeFirst, removeLast, replaceAll, retainAll, reversed, sort, spliterator, subList, toArray, toArray
-
Field Details
-
Empty
-
-
Constructor Details
-
LList
public LList()Do not use - only public for serialization!
-
-
Method Details
-
listLength
A safe function to count the length of a list.- Parameters:
obj
- the putative list to measureallowOtherSequence
- if a non-List Sequence is seen, allow that- Returns:
- the length, or -1 for a circular list, or -2 for a dotted list
-
equals
- Specified by:
equals
in interfaceCollection<Object>
- Specified by:
equals
in interfaceList<Object>
- Overrides:
equals
in classAbstractSequence<Object>
-
compareTo
- Specified by:
compareTo
in interfaceComparable
-
size
public int size()Description copied from interface:Sequence
See java.util.List. -
isEmpty
public boolean isEmpty()Description copied from interface:Sequence
True is this sequence contains no elements. -
getIterator
- Overrides:
getIterator
in classAbstractSequence<Object>
-
createPos
public int createPos(int index, boolean isAfter) Description copied from class:AbstractSequence
Generate a position at a given index. The result is a position cookie that must be free'd with releasePos.- Overrides:
createPos
in classAbstractSequence<Object>
- Parameters:
index
- offset from beginning of desired positionisAfter
- should the position have the isAfter property
-
createRelativePos
public int createRelativePos(int pos, int delta, boolean isAfter) - Overrides:
createRelativePos
in classAbstractSequence<Object>
-
hasNext
public boolean hasNext(int ipos) - Overrides:
hasNext
in classAbstractSequence<Object>
-
nextPos
public int nextPos(int ipos) Description copied from class:AbstractSequence
Return the next position following the argument. The new position has the isAfter property. The argument is implicitly released (as in releasePos). Returns 0 if we are already at end of file.- Overrides:
nextPos
in classAbstractSequence<Object>
-
getPosNext
Description copied from class:AbstractSequence
Get the element following the specified position.- Overrides:
getPosNext
in classAbstractSequence<Object>
- Parameters:
ipos
- the specified position.- Returns:
- the following element, or eofValue if there is none. Called by SeqPosition.getNext. FIXME Should change eof handling so return type can be E.
-
getPosPrevious
Description copied from class:AbstractSequence
Get the element before the specified position.- Overrides:
getPosPrevious
in classAbstractSequence<Object>
- Parameters:
ipos
- the specified position.- Returns:
- the following element, or eofValue if there is none. FIXME Should change eof handling so return type can be E.
-
setPosNext
- Overrides:
setPosNext
in classAbstractSequence<Object>
-
setPosPrevious
- Overrides:
setPosPrevious
in classAbstractSequence<Object>
-
get
Description copied from interface:Sequence
See java.util.List. -
length
-
boundedHash
public int boundedHash(int seed, int limit) Description copied from interface:BoundedHashable
Calculate a hash code for this object.- Specified by:
boundedHash
in interfaceBoundedHashable
- Overrides:
boundedHash
in classAbstractSequence<Object>
- Parameters:
seed
- The seed is an initial value, or the accumulated hash code from previous elements in a containing object. Using zero as the seed is fine.limit
- A limit on the number of sub-elements whose hash we should calculate. This guards against cycles. Any recursive calls should be done with a smaller value of limit, and no recursive calls must be done when the limit is zero.- Returns:
- A well-dispersed hash code.
The result is not compatible with
Object#hashCode
.
-
hashCode
public int hashCode()- Specified by:
hashCode
in interfaceCollection<Object>
- Specified by:
hashCode
in interfaceList<Object>
- Overrides:
hashCode
in classAbstractSequence<Object>
-
makeList
-
makeList
-
makeList
-
consume
- Specified by:
consume
in interfaceConsumable
- Overrides:
consume
in classAbstractSequence<Object>
-
readExternal
- Specified by:
readExternal
in interfaceExternalizable
- Throws:
IOException
ClassNotFoundException
-
writeExternal
- Specified by:
writeExternal
in interfaceExternalizable
- Throws:
IOException
-
readResolve
- Throws:
ObjectStreamException
-
list1
-
list2
-
list3
-
list4
-
chain1
Utility function used by compiler when inlining `list'. -
chain4
Utility function used by compiler when inlining `list'. -
reverseInPlace
Reverse a list in place, by modifying the cdr fields. -
consX
SRFI-1's cons* and Common Lisp's list* function. -
toString
- Overrides:
toString
in classAbstractSequence<Object>
-
checkNonList
Helper to protect against pathological LLists (neithr Pair nor Empty).
-