qblox_scheduler.helpers.linked_list#

Doubly linked list.

Attributes#

T

Classes#

DLinkedListNode

A node in a DLinkedList.

DLinkedList

A doubly linked list.

Module Contents#

T[source]#
class DLinkedListNode(value: T, prev: DLinkedListNode[T] | None = None, next: DLinkedListNode[T] | None = None)[source]#

Bases: Generic[T]

A node in a DLinkedList.

value: T[source]#
__prev = None[source]#
__next = None[source]#
property prev: DLinkedListNode[T] | None[source]#

The node before this one.

property next: DLinkedListNode[T] | None[source]#

The node after this one.

reverse_from_head() None[source]#

If this node is the head of the list, reverse the list, turning this node into the tail.

Note: if this node is not the head, throw an error.

class DLinkedList(from_iterable: collections.abc.Iterable[T] | None = None)[source]#

Bases: collections.abc.MutableSequence[T]

A doubly linked list.

__head: DLinkedListNode[T] | None = None[source]#
__tail: DLinkedListNode[T] | None = None[source]#
__size_cache: int | None = None[source]#
__get_content_str(format_fn: collections.abc.Callable[[object], str]) str[source]#
property size: int[source]#

The length of this list.

_reset_size_cache() None[source]#
node_at(index: int) DLinkedListNode[T][source]#

Return the DLinkedListNode at the index.

iter_nodes(*, reverse: bool = False) collections.abc.Iterator[DLinkedListNode[T]][source]#

Return an iterator of the nodes of the list.

insert(index: int, value: T) None[source]#

Insert value into the list at the given index.

insert_after(node: DLinkedListNode[T], value: T) None[source]#

Insert value into the list after the given node.

insert_before(node: DLinkedListNode[T], value: T) None[source]#

Insert value into the list before the given node.

index(value: T, start: int = 0, stop: int = ...) int[source]#

Return first index of value.

Raises ValueError if the value is not present. Optional arguments start and end are interpreted as in slice notation.

count(value: T) int[source]#

Count the number of list elements equal to value.

append(value: T) None[source]#

Add value to the right side of the list.

clear() None[source]#

Remove all elements from the list leaving it with length 0.

reverse() None[source]#

Reverse the elements of the list in-place and then return None.

extend(values: collections.abc.Iterable[T]) None[source]#

Extend the right side of the list by appending elements from the iterable argument.

pop(index: int = -1) T[source]#

Remove and return an element from the list at index.

By default, removes from the right side of the list. If no elements are present, raises an IndexError.

remove(value: T) None[source]#

Remove the first occurrence of value. If not found, raises a ValueError.

appendleft(value: T) None[source]#

Add value to the left side of the linked list.

copy() DLinkedList[T][source]#

Create a shallow copy of the linked list.

extendleft(values: collections.abc.Iterable[T]) None[source]#

Extend the left side of the linked list by appending elements from iterable.

Note, the series of left appends results in reversing the order of elements in the iterable argument.

popleft() T[source]#

Remove and return an element from the left side of the linked list.

If no elements are present, raises an IndexError.