Package gnu.lists

Class LList

  • All Implemented Interfaces:
    BoundedHashable, Consumable, Sequence<java.lang.Object>, java.io.Externalizable, java.io.Serializable, java.lang.Comparable, java.lang.Iterable<java.lang.Object>, java.util.Collection<java.lang.Object>, java.util.List<java.lang.Object>
    Direct Known Subclasses:
    EmptyList, Pair

    public class LList
    extends ExtSequence<java.lang.Object>
    implements Sequence<java.lang.Object>, java.io.Externalizable, java.lang.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:
    Serialized Form
    • Field Detail

    • Constructor Detail

      • LList

        public LList()
        Do not use - only public for serialization!
    • Method Detail

      • listLength

        public static int listLength​(java.lang.Object obj,
                                     boolean allowOtherSequence)
        A safe function to count the length of a list.
        Parameters:
        obj - the putative list to measure
        allowOtherSequence - 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

        public boolean equals​(java.lang.Object obj)
        Specified by:
        equals in interface java.util.Collection<java.lang.Object>
        Specified by:
        equals in interface java.util.List<java.lang.Object>
        Overrides:
        equals in class AbstractSequence<java.lang.Object>
      • compareTo

        public int compareTo​(java.lang.Object obj)
        Specified by:
        compareTo in interface java.lang.Comparable
      • size

        public int size()
        Description copied from interface: Sequence
        See java.util.List.
        Specified by:
        size in interface java.util.Collection<java.lang.Object>
        Specified by:
        size in interface java.util.List<java.lang.Object>
        Specified by:
        size in interface Sequence<java.lang.Object>
        Overrides:
        size in class AbstractSequence<java.lang.Object>
      • isEmpty

        public boolean isEmpty()
        Description copied from interface: Sequence
        True is this sequence contains no elements.
        Specified by:
        isEmpty in interface java.util.Collection<java.lang.Object>
        Specified by:
        isEmpty in interface java.util.List<java.lang.Object>
        Specified by:
        isEmpty in interface Sequence<java.lang.Object>
        Overrides:
        isEmpty in class AbstractSequence<java.lang.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 class AbstractSequence<java.lang.Object>
        Parameters:
        index - offset from beginning of desired position
        isAfter - should the position have the isAfter property
      • createRelativePos

        public int createRelativePos​(int pos,
                                     int delta,
                                     boolean isAfter)
        Overrides:
        createRelativePos in class AbstractSequence<java.lang.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 class AbstractSequence<java.lang.Object>
      • getPosNext

        public java.lang.Object getPosNext​(int ipos)
        Description copied from class: AbstractSequence
        Get the element following the specified position.
        Overrides:
        getPosNext in class AbstractSequence<java.lang.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

        public java.lang.Object getPosPrevious​(int ipos)
        Description copied from class: AbstractSequence
        Get the element before the specified position.
        Overrides:
        getPosPrevious in class AbstractSequence<java.lang.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

        protected void setPosNext​(int ipos,
                                  java.lang.Object value)
        Overrides:
        setPosNext in class AbstractSequence<java.lang.Object>
      • setPosPrevious

        protected void setPosPrevious​(int ipos,
                                      java.lang.Object value)
        Overrides:
        setPosPrevious in class AbstractSequence<java.lang.Object>
      • get

        public java.lang.Object get​(int index)
        Description copied from interface: Sequence
        See java.util.List.
        Specified by:
        get in interface java.util.List<java.lang.Object>
        Specified by:
        get in interface Sequence<java.lang.Object>
        Overrides:
        get in class AbstractSequence<java.lang.Object>
      • length

        public static final int length​(java.lang.Object arg)
      • boundedHash

        public int boundedHash​(int seed,
                               int limit)
        Description copied from interface: BoundedHashable
        Calculate a hash code for this object.
        Specified by:
        boundedHash in interface BoundedHashable
        Overrides:
        boundedHash in class AbstractSequence<java.lang.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 interface java.util.Collection<java.lang.Object>
        Specified by:
        hashCode in interface java.util.List<java.lang.Object>
        Overrides:
        hashCode in class AbstractSequence<java.lang.Object>
      • makeList

        public static LList makeList​(java.util.List vals)
      • makeList

        public static LList makeList​(java.lang.Object[] vals,
                                     int offset,
                                     int length)
      • makeList

        public static LList makeList​(java.lang.Object[] vals,
                                     int offset)
      • readExternal

        public void readExternal​(java.io.ObjectInput in)
                          throws java.io.IOException,
                                 java.lang.ClassNotFoundException
        Specified by:
        readExternal in interface java.io.Externalizable
        Throws:
        java.io.IOException
        java.lang.ClassNotFoundException
      • writeExternal

        public void writeExternal​(java.io.ObjectOutput out)
                           throws java.io.IOException
        Specified by:
        writeExternal in interface java.io.Externalizable
        Throws:
        java.io.IOException
      • readResolve

        public java.lang.Object readResolve()
                                     throws java.io.ObjectStreamException
        Throws:
        java.io.ObjectStreamException
      • list1

        public static Pair list1​(java.lang.Object arg1)
      • list2

        public static Pair list2​(java.lang.Object arg1,
                                 java.lang.Object arg2)
      • list3

        public static Pair list3​(java.lang.Object arg1,
                                 java.lang.Object arg2,
                                 java.lang.Object arg3)
      • list4

        public static Pair list4​(java.lang.Object arg1,
                                 java.lang.Object arg2,
                                 java.lang.Object arg3,
                                 java.lang.Object arg4)
      • chain1

        public static Pair chain1​(Pair old,
                                  java.lang.Object arg1)
        Utility function used by compiler when inlining `list'.
      • chain4

        public static Pair chain4​(Pair old,
                                  java.lang.Object arg1,
                                  java.lang.Object arg2,
                                  java.lang.Object arg3,
                                  java.lang.Object arg4)
        Utility function used by compiler when inlining `list'.
      • reverseInPlace

        public static LList reverseInPlace​(java.lang.Object list)
        Reverse a list in place, by modifying the cdr fields.
      • consX

        public static java.lang.Object consX​(java.lang.Object[] args)
        SRFI-1's cons* and Common Lisp's list* function.
      • checkNonList

        public static java.lang.Object checkNonList​(java.lang.Object rest)
        Helper to protect against pathological LLists (neithr Pair nor Empty).