Esempio n. 1
0
    def search(self, key: Any) -> RBNode:
        """Look for a node by a given key.

        See Also
        --------
        :py:meth:`trees.binary_trees.binary_tree.BinaryTree.search`.
        """
        temp: Union[RBNode, LeafNode] = self.root
        while isinstance(temp, RBNode):
            if key < temp.key:
                temp = temp.left
            elif key > temp.key:
                temp = temp.right
            else:  # Key found
                return temp
        raise tree_exceptions.KeyNotFoundError(key=key)
    def search(self, key: Any) -> binary_tree.Node:
        """Look for a node by a given key.

        See Also
        --------
        :py:meth:`trees.binary_trees.binary_tree.BinaryTree.search`.
        """
        current = self.root

        while current:
            if key == current.key:
                return current
            elif key < current.key:
                current = current.left
            else:  # key > current.key:
                current = current.right
        raise tree_exceptions.KeyNotFoundError(key=key)
Esempio n. 3
0
    def search(self, key: Any) -> SingleThreadNode:
        """Look for a node by a given key.

        See Also
        --------
        :py:meth:`trees.binary_trees.binary_tree.BinaryTree.search`.
        """
        current = self.root
        while current:
            if key == current.key:
                return current  # type: ignore
            elif key < current.key:
                current = current.left
            else:  # key > current.key
                if current.isThread is False:
                    current = current.right
                else:
                    break
        raise tree_exceptions.KeyNotFoundError(key=key)