protected function nodeFloor($key, ?RedBlackNode $node): ?RedBlackNode
    {
        if ($node === null) {
            return null;
        }

        $comp = $this->comparator->compare($key, $node->key());

        if ($comp === 0) {
            return $node;
        }
        if ($comp < 0) {
            return $this->nodeFloor($key, $node->left());
        }
        $right = $this->nodeFloor($key, $node->right());
        if ($right !== null) {
            return $right;
        }

        return $node;
    }