Module Functional :: Class LList
[show private]
[frames] | no frames]

Class LList

source code

object --+
         |
        LList

Immutable linked-list datatype.

Unlike python lists, allows constant-time addition to the head and fast tail slices. Length and hash methods are also constant-time.



Instance Methods [show private]
 
__init__(self, head, tail)
Create a list consisting of head appended to the list given by tail.
source code
 
__iter__(self)
Iterate over the elements of this list.
source code
 
__repr__(self)
Return a string which could be 'eval'ed to yield this LList.
source code
 
__str__(self)
Return a string representation of this list.
source code
 
__eq__(self, other)
Return True iff the LList objects have the same contents and order.
source code
 
__ne__(self, other) source code
 
__cmp__(self, other)
Compare two LList objects in lexicographic order: a list prefix is "less than" the full list.
source code
 
__hash__(self)
Return a hash of the contents of this list.
source code
 
__len__(self)
Return the length of this list.
source code
 
__nonzero__(self)
Return True iff the list has at least one item in it.
source code
 
__getitem__(self, key)
Returns an element or slice of this LList.
source code
 
toList(self)
Create a python list from this LList.
source code

Inherited from object: __delattr__, __getattribute__, __new__, __reduce__, __reduce_ex__, __setattr__

Static Methods [show private]
 
fromList(lst)
Create an LList from a python list.
source code
Instance Variables [show private]
  head
The item at the start of this list.
  tail
The list of items following the head.
  hash
Hashcode for this list.
  len
Length of this list.
Properties [show private]

Inherited from object: __class__

Method Details [show private]

__hash__(self)
(Hashing function)

source code 

Return a hash of the contents of this list.

The hashcode for a LList is:

hash(self.head) + (17 * hash(self.tail))
Overrides: object.__hash__