priority_search_tree.print_helpers¶
This module contains printing helper methods for PST.
Example
Tree can be printed into console with the following code:
from priority_search_tree import PrioritySearchTree
from priority_search_tree.print_helpers import print_tree
# create PST
pst = PrioritySearchTree([(0, 0), (1, 1), (2, 2), (3, 6), (4, 3), (5, 4), (6, 5), (7, 8), (8, 7)])
# print PST
print_tree(pst)
As result next text will be printed into sys.stdout:
# print result
(5, 4):(7, 8)
├────(3, 6):(3, 6)
│ ├────(2, 2):(2, 2)
│ │ ├────(1, 1):(1, 1)
│ │ │ ├────(0, 0):(0, 0)
│ │ │ └────(1, 1):[NULL_VALUE]
│ │ └────(2, 2):[NULL_VALUE]
│ └────(4, 3):(4, 3)
│ ├────(3, 6):[NULL_VALUE]
│ └────(4, 3):[NULL_VALUE]
└────(7, 8):(8, 7)
├────(6, 5):(6, 5)
│ ├────(5, 4):(5, 4)
│ └────(6, 5):[NULL_VALUE]
└────(8, 7):[NULL_VALUE]
├────(7, 8):[NULL_VALUE]
└────(8, 7):[NULL_VALUE]
- priority_search_tree.print_helpers.print_set(ps_set: PrioritySearchSet, indent_width=4, file=None, flush=False)[source]¶
Prints string representation of the PSS to
sys.stdout- Parameters:
ps_set (
PrioritySearchSet) – PSS to be visualisedindent_width (
int) – number of spaces for indentation. Default value is4file – a file-like object (stream); defaults to the current
sys.stdout.flush (
bool) – whether to forcibly flush the stream. Default value isFalse
- priority_search_tree.print_helpers.print_tree(tree: PrioritySearchTree, indent_width=4, file=None, flush=False)[source]¶
Prints string representation of the PST to
sys.stdout- Parameters:
tree (
PrioritySearchTree) – PST to be visualisedindent_width (
int) – number of spaces for indentation. Default value is4file – a file-like object (stream); defaults to the current
sys.stdout.flush (
bool) – whether to forcibly flush the stream. Default value isFalse
- priority_search_tree.print_helpers.repr_set(ps_set: PrioritySearchSet, indent_width: int = 4) str[source]¶
Returns string representation of the PSS
- Parameters:
ps_set (
PrioritySearchSet) – PSS to be visualisedindent_width (
int) – number of spaces for indentation. Default value is4
- Returns:
string PSS representation
- Return type:
str
- priority_search_tree.print_helpers.repr_tree(tree: PrioritySearchTree, indent_width: int = 4) str[source]¶
Returns string representation of the PST
- Parameters:
tree (
PrioritySearchTree) – PST to be visualisedindent_width (
int) – number of spaces for indentation. Default value is4
- Returns:
string PST representation
- Return type:
str