class documentation

class _DoubleLinkedList(object):

Constructor: _DoubleLinkedList(elements)

View In Hierarchy

A double linkked list used by the LRU cache.

Method __init__ The default constructor.
Method __iter__ Iterate over the values in this list.
Method __repr__ Return a string representing this object
Method append Append an element to the end of this list.
Method clear Empty this list.
Method iter_values Iterate over all values.
Method prepend Prepend an element at the front of this list.
Method remove_element Remove a list element (not a value!).
Method remove_first Remove the first element of this list.
Method remove_last Remove the last element of this list.
Method to_list Return a python list of the values in this list.
Instance Variable head the first element in this list
Instance Variable length current length of list
Instance Variable tail the last element in this list
def __init__(self, elements=None):

The default constructor.

Parameters
elements:iterator or Noneif specified, add all elements from this iterable to this list
def __iter__(self):

Iterate over the values in this list.

Yields
same as added to this listthe values in this list
def __repr__(self):

Return a string representing this object

Returns
stra string representing this object
def append(self, value):

Append an element to the end of this list.

If value if a _DoubleLinkedListElement, it will not be wrapped and instead used directly.

Complexity is O(1).

Parameters
value:anyvalue or element to append
Returns
_DoubleLinkedListElementthe added list element
def clear(self):

Empty this list.

Complexity is O(1).

def iter_values(self):

Iterate over all values.

Yields
same as added to this listthe values in this list
def prepend(self, value):

Prepend an element at the front of this list.

If value if a _DoubleLinkedListElement, it will not be wrapped and instead used directly.

Complexity is O(1).

Parameters
value:anyvalue or element to prepend
Returns
_DoubleLinkedListElementthe added list element
def remove_element(self, element):

Remove a list element (not a value!).

Complexity is O(1).

Parameters
element:_DoubleLinkedListElementelement to remove
Raises
ValueErrorif element is not part of this list
def remove_first(self):

Remove the first element of this list.

Complexity is O(1).

Raises
IndexErrorif there is no first element
def remove_last(self):

Remove the last element of this list.

Complexity is O(1).

Raises
IndexErrorif there is no last element
def to_list(self):

Return a python list of the values in this list.

Complexity is O(n).

Returns
lista list containing the values in this list

the first element in this list

length: int =

current length of list

the last element in this list