Linked list model to represent linear or circular sequences.
Classes
|
A generic double linked list class. |
Node constructor. |
|
|
A match object. |
|
A node in a linked list. |
Exceptions
Generic linked list exception. |
|
Indices were out of bounds for LinkedList. |
jdna.linked_list.
DoubleLinkedList
(data: Sequence[Any] = None, first: jdna.linked_list.Node = None, cyclic: bool = False)[source]¶Bases: object
A generic double linked list class.
linked list construction.
data (iterable) – iterable data
first (Node) – first node
circular
¶Alias for cyclic.
collect_nodes
(nodes)[source]¶Return all visisted nodes and return an unordered set of nodes.
all visited nodes
set
compare
(other: jdna.linked_list.DoubleLinkedList) → bool[source]¶Compares two linked lists. If both are cyclic, will attempt to reindex.
other (DoubleLinkedList) – other linked list
whether sequence data is equivalent
bool
copy_slice
(start: jdna.linked_list.Node, end: jdna.linked_list.Node) → jdna.linked_list.DoubleLinkedList[source]¶Return a copy of the sequence between ‘start’ and ‘end’ nodes.
If start is None, return the slice copy from head to end. If end is None, return copy from start to tail. If both start and end are None return None.
find_iter
(query: jdna.linked_list.DoubleLinkedList, min_query_length: int = None, direction: int = <Direction.FORWARD: 1>, protocol: Callable = None, depth: int = None)[source]¶Iteratively finds positions that match the query.
query (DoubleLinkedList) – query list to find
min_query_length (inst) – the minimum number of matches to return. If None, find_iter will only return complete matches
direction (int or tuple) – If Direction.FORWARD (+1), find iter will search from the query head and search forward, potentially leaving a ‘tail’ overhang on the query. If Direction.REVERSE (-1), find iter will search from the query tail and search reverse, potentially leaving a ‘head’ overhang on the query. If a tuple, the template_direction and query_direction are set respectively.
protocol (callable) – the callable taking two parameters (as Node) to compare during find. If None, defaults to ‘equivalent’
list of LinkedListMatches
list
inclusive_range
(i: int, j: int) → Generator[jdna.linked_list.Node, None, None][source]¶Return generator for inclusive nodes between index i and j.
If i is None, assume i is the head node.
new_slice
(start: jdna.linked_list.Node, end: jdna.linked_list.Node) → jdna.linked_list.DoubleLinkedList[source]¶Return a copy of the sequence between ‘start’ and ‘end’ nodes)
jdna.linked_list.
EmptyNode
[source]¶Bases: jdna.linked_list.Node
Node constructor. Stores a single piece of data.
data (any) – data
_break_connections
()¶Break connections in this node.
_complete_match
(node: jdna.linked_list.Node, next_method: Callable) → bool¶Return whether the longest match between two nodes is equivalent.
node (Node) – the node to compare
next_method (callable) – how to obtain the next node
whether the longest match between two nodes is equivalent
bool
add_next
(data)¶Create a new node and add to next.
data (any) – any data
the new node
add_prev
(data)¶Create a new node and add to previous.
data (any) – any data
the new node
cut_prev
()¶Cut the previous node, return the cut node.
the cut (previous) node
equivalent
(other: jdna.linked_list.Node) → bool¶Evaluates whether two nodes hold the same data.
find_first
() → jdna.linked_list.Node¶Find the head node.
find_last
() → jdna.linked_list.Node¶Find the tail node.
fwd
(stop_node: Optional[jdna.linked_list.Node] = None, stop_criteria: Callable = None) → Generator¶Propogates forwards until stop node is visited or stop criteria is reached.
stop_node –
stop_criteria –
longest_match
(node: jdna.linked_list.Node, next_method: Callable = None) → Tuple[jdna.linked_list.Node, jdna.linked_list.Node]¶Find the longest match between two linked_lists.
node (Node) – the node to compare
next_method (callable) – how to obtain the next node
list of tuples containing matching nodes
list
remove
()¶Remove node from linked list, connecting the previous and next nodes together.
None
None
rev
(stop_node: Optional[jdna.linked_list.Node] = None, stop_criteria: Callable = None) → Generator[jdna.linked_list.Node, None, None]¶Propogates backwards until stop node is visited or stop criteria is reached.
stop_node –
stop_criteria –
set_next
(node: jdna.linked_list.Node)¶Set the next node.
node –
set_prev
(node: jdna.linked_list.Node)¶Set the previous node.
node –
swap
()¶Swap the previous and next nodes.
None
None
jdna.linked_list.
LinkedListException
[source]¶Bases: Exception
Generic linked list exception.
with_traceback
()¶Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
jdna.linked_list.
LinkedListIndexError
[source]¶Bases: jdna.linked_list.LinkedListException
, IndexError
Indices were out of bounds for LinkedList.
with_traceback
()¶Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
jdna.linked_list.
LinkedListMatch
(template_bounds: Tuple[jdna.linked_list.Node, jdna.linked_list.Node], query_bounds: Tuple[jdna.linked_list.Node, jdna.linked_list.Node], template: jdna.linked_list.DoubleLinkedList, query: jdna.linked_list.DoubleLinkedList)[source]¶Bases: object
A match object.
batch_create
(template_bounds_list: List[Tuple[jdna.linked_list.Node, jdna.linked_list.Node]], query_bounds_list: List[Tuple[jdna.linked_list.Node, jdna.linked_list.Node]], template: jdna.linked_list.DoubleLinkedList, query: jdna.linked_list.DoubleLinkedList) → List[jdna.linked_list.LinkedListMatch][source]¶Efficiently create several LinkedListMatches from lists of template starts/ends and query starts/ends.
template_bounds_list (template DoubleLinkedList) – list of 2 len tuples containing starts and ends from a template
query_bounds_list (query DoubleLinkedList) – list of 2 len tuples containing starts and ends from a query
template (DoubleLinkedList) – the template
query (DoubleLinkedList) – the query
matchese
list of LinkedListMatch
jdna.linked_list.
Node
(data)[source]¶Bases: object
A node in a linked list.
Node constructor. Stores a single piece of data.
data (any) – data
_complete_match
(node: jdna.linked_list.Node, next_method: Callable) → bool[source]¶Return whether the longest match between two nodes is equivalent.
node (Node) – the node to compare
next_method (callable) – how to obtain the next node
whether the longest match between two nodes is equivalent
bool
add_next
(data)[source]¶Create a new node and add to next.
data (any) – any data
the new node
add_prev
(data)[source]¶Create a new node and add to previous.
data (any) – any data
the new node
cut_prev
()[source]¶Cut the previous node, return the cut node.
the cut (previous) node
equivalent
(other: jdna.linked_list.Node) → bool[source]¶Evaluates whether two nodes hold the same data.
fwd
(stop_node: Optional[jdna.linked_list.Node] = None, stop_criteria: Callable = None) → Generator[source]¶Propogates forwards until stop node is visited or stop criteria is reached.
stop_node –
stop_criteria –
longest_match
(node: jdna.linked_list.Node, next_method: Callable = None) → Tuple[jdna.linked_list.Node, jdna.linked_list.Node][source]¶Find the longest match between two linked_lists.
node (Node) – the node to compare
next_method (callable) – how to obtain the next node
list of tuples containing matching nodes
list
remove
()[source]¶Remove node from linked list, connecting the previous and next nodes together.
None
None
rev
(stop_node: Optional[jdna.linked_list.Node] = None, stop_criteria: Callable = None) → Generator[jdna.linked_list.Node, None, None][source]¶Propogates backwards until stop node is visited or stop criteria is reached.
stop_node –
stop_criteria –
set_next
(node: jdna.linked_list.Node)[source]¶Set the next node.
node –