Tools for finding paths through composite data structures.
Every walk_{form} function returns a list of paths. Each path is a list of
nodes that starts with the start node and ends with the stop node.
Contents
walk: returns path(s) through any recognized composite form. walk_adjacency: returns path(s) through an adjacency list. walk_edges: returns path(s) through an edge list. walk_matrix: returns path(s) through an adjacency matrix. walk_parallel: returns path(s) through a parallel structure. walk_serial: returns path(s) through a serial structure.
walk(item, start=None, stop=None)
¶
Returns all paths in any recognized composite form.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Any
|
composite data structure or raw form in which to find paths. |
required |
start
|
Hashable | Sequence[Hashable] | None
|
node (or list of nodes) to start paths from. If it is |
None
|
stop
|
Hashable | Sequence[Hashable] | None
|
node (or list of nodes) to stop paths at. If it is |
None
|
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
if there is no walk function for the form of
|
Returns:
| Type | Description |
|---|---|
RawParallel
|
A list of possible paths (each path is a list of nodes) from |
Source code in src/holden/traverse.py
walk_adjacency(item, start, stop, path=None)
¶
Returns all paths in item from start to stop.
A path never visits the same node twice, so cycles cannot cause the search to run forever. Paths are returned in a deterministic order.
The code here is adapted from: https://www.python.org/doc/essays/graphs/
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Adjacency | RawAdjacency
|
item in which to find paths. |
required |
start
|
Hashable
|
node to start paths from. |
required |
stop
|
Hashable
|
node to stop paths at. |
required |
path
|
Sequence[Hashable] | None
|
nodes to place in front of every returned path. Defaults to
|
None
|
Returns:
| Type | Description |
|---|---|
RawParallel
|
A list of possible paths (each path is a list of nodes) from |
Source code in src/holden/traverse.py
walk_edges(item, start, stop, path=None)
¶
Returns all paths in item from start to stop.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Edges | RawEdges
|
item in which to find paths. |
required |
start
|
Hashable
|
node to start paths from. |
required |
stop
|
Hashable
|
node to stop paths at. |
required |
path
|
Sequence[Hashable] | None
|
nodes to place in front of every returned path. Defaults to
|
None
|
Returns:
| Type | Description |
|---|---|
RawParallel
|
A list of possible paths (each path is a list of nodes) from |
Source code in src/holden/traverse.py
walk_matrix(item, start, stop, path=None)
¶
Returns all paths in item from start to stop.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Matrix | RawMatrix
|
item in which to find paths. |
required |
start
|
Hashable
|
node to start paths from. |
required |
stop
|
Hashable
|
node to stop paths at. |
required |
path
|
Sequence[Hashable] | None
|
nodes to place in front of every returned path. Defaults to
|
None
|
Returns:
| Type | Description |
|---|---|
RawParallel
|
A list of possible paths (each path is a list of nodes) from |
Source code in src/holden/traverse.py
walk_parallel(item, start, stop)
¶
Returns all paths in item from start to stop.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Parallel | RawParallel
|
item in which to find paths. |
required |
start
|
Hashable
|
node to start paths from. |
required |
stop
|
Hashable
|
node to stop paths at. |
required |
Returns:
| Type | Description |
|---|---|
RawParallel
|
A list of possible paths (each path is a list of nodes) from |
Source code in src/holden/traverse.py
walk_serial(item, start, stop)
¶
Returns all paths in item from start to stop.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Serial | RawSerial
|
item in which to find paths. |
required |
start
|
Hashable
|
node to start paths from. |
required |
stop
|
Hashable
|
node to stop paths at. |
required |
Returns:
| Type | Description |
|---|---|
RawParallel
|
A list with the single path from the first |