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
noIntsFields 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 TypeMethodDescriptionintboundedHash(int seed, int limit) Calculate a hash code for this object.static PairUtility function used by compiler when inlining `list'.static PairUtility function used by compiler when inlining `list'.static ObjectcheckNonList(Object rest) Helper to protect against pathological LLists (neithr Pair nor Empty).intvoidstatic ObjectSRFI-1's cons* and Common Lisp's list* function.intcreatePos(int index, boolean isAfter) Generate a position at a given index.intcreateRelativePos(int pos, int delta, boolean isAfter) booleanget(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.inthashCode()booleanhasNext(int ipos) booleanisEmpty()True is this sequence contains no elements.static final intstatic Pairstatic Pairstatic Pairstatic Pairstatic intlistLength(Object obj, boolean allowOtherSequence) A safe function to count the length of a list.static LListstatic LListstatic LListintnextPos(int ipos) Return the next position following the argument.voidstatic LListreverseInPlace(Object list) Reverse a list in place, by modifying the cdr fields.protected voidsetPosNext(int ipos, Object value) protected voidsetPosPrevious(int ipos, Object value) intsize()See java.util.List.toString()voidMethods inherited from class gnu.lists.ExtSequence
copyPos, isAfterPos, nextIndex, releasePosMethods 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, unsupportedExceptionMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods 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:
equalsin interfaceCollection<Object>- Specified by:
equalsin interfaceList<Object>- Overrides:
equalsin classAbstractSequence<Object>
-
compareTo
- Specified by:
compareToin interfaceComparable
-
size
public int size()Description copied from interface:SequenceSee java.util.List. -
isEmpty
public boolean isEmpty()Description copied from interface:SequenceTrue is this sequence contains no elements. -
getIterator
- Overrides:
getIteratorin classAbstractSequence<Object>
-
createPos
public int createPos(int index, boolean isAfter) Description copied from class:AbstractSequenceGenerate a position at a given index. The result is a position cookie that must be free'd with releasePos.- Overrides:
createPosin 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:
createRelativePosin classAbstractSequence<Object>
-
hasNext
public boolean hasNext(int ipos) - Overrides:
hasNextin classAbstractSequence<Object>
-
nextPos
public int nextPos(int ipos) Description copied from class:AbstractSequenceReturn 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:
nextPosin classAbstractSequence<Object>
-
getPosNext
Description copied from class:AbstractSequenceGet the element following the specified position.- Overrides:
getPosNextin 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:AbstractSequenceGet the element before the specified position.- Overrides:
getPosPreviousin 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:
setPosNextin classAbstractSequence<Object>
-
setPosPrevious
- Overrides:
setPosPreviousin classAbstractSequence<Object>
-
get
Description copied from interface:SequenceSee java.util.List. -
length
-
boundedHash
public int boundedHash(int seed, int limit) Description copied from interface:BoundedHashableCalculate a hash code for this object.- Specified by:
boundedHashin interfaceBoundedHashable- Overrides:
boundedHashin 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:
hashCodein interfaceCollection<Object>- Specified by:
hashCodein interfaceList<Object>- Overrides:
hashCodein classAbstractSequence<Object>
-
makeList
-
makeList
-
makeList
-
consume
- Specified by:
consumein interfaceConsumable- Overrides:
consumein classAbstractSequence<Object>
-
readExternal
- Specified by:
readExternalin interfaceExternalizable- Throws:
IOExceptionClassNotFoundException
-
writeExternal
- Specified by:
writeExternalin 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:
toStringin classAbstractSequence<Object>
-
checkNonList
Helper to protect against pathological LLists (neithr Pair nor Empty).
-