From 85538b96a0eeb3498d3f9bf106d4a5a4368a222e Mon Sep 17 00:00:00 2001 From: Scott Gasch Date: Sun, 7 May 2023 21:18:38 -0700 Subject: [PATCH] Improve docs on bst.py again. --- src/pyutils/collectionz/bst.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/pyutils/collectionz/bst.py b/src/pyutils/collectionz/bst.py index 3a0fae9..dec2656 100644 --- a/src/pyutils/collectionz/bst.py +++ b/src/pyutils/collectionz/bst.py @@ -9,6 +9,14 @@ from typing import Any, Generator, List, Optional, Protocol class Comparable(Protocol): + """Anything that implements basic comparison methods such that it + can be compared to other instances of the same type. + + Check out :meth:`functools.total_ordering` + (https://docs.python.org/3/library/functools.html#functools.total_ordering) + for an easy way to make your type comparable. + """ + @abstractmethod def __lt__(self, other: Any) -> bool: ... @@ -24,14 +32,13 @@ class Comparable(Protocol): class Node: def __init__(self, value: Comparable) -> None: - """A BST node. Note that value can be anything as long as it - is comparable with other instances of itself. Check out - :meth:`functools.total_ordering` - (https://docs.python.org/3/library/functools.html#functools.total_ordering) + """A BST node. Just a left and right reference along with a + value. Note that value can be anything as long as it + is :class:`Comparable` with other instances of itself. Args: - value: a reference to the value of the node. Must be comparable - to other values. + value: a reference to the value of the node. Must be + :class:`Comparable` to other values. """ self.left: Optional[Node] = None -- 2.47.1