src/Collection/Tree/RedBlackSearchTree.php
protected function nodeRank($key, ?RedBlackNode $node): int
    {
        if ($node === null) {
            return 0;
        }

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

        if ($comp < 0) {
            return $this->nodeRank($key, $node->left());
        }
        if ($comp > 0) {
            return 1 + $this->nodeSize($node->left()) + $this->nodeRank($key, $node->right());
        }

        return $this->nodeSize($node->left());
    }
protected function nodeRank($key, ?RedBlackNode $node): int
    {
        if ($node === null) {
            return 0;
        }

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

        if ($comp < 0) {
            return $this->nodeRank($key, $node->left());
        }
        if ($comp > 0) {
            return 1 + $this->nodeSize($node->left()) + $this->nodeRank($key, $node->right());
        }

        return $this->nodeSize($node->left());
    }
protected function nodeRank ( $ key , ? RedBlackNode $ node ) : int { if ( $ node === null ) { return 0 ; } $ comp = $ this -> comparator -> compare ( $ key , $ node -> key ( ) ) ; if ( $ comp < 0 ) { return $ this -> nodeRank ( $ key , $ node -> left ( ) ) ; } if ( $ comp > 0 ) { return 1 + $ this -> nodeSize ( $ node -> left ( ) ) + $ this -> nodeRank ( $ key , $ node -> right ( ) ) ; } return $ this -> nodeSize ( $ node -> left ( ) ) ; }
Retrieves the rank for a key in a subtree

@param mixed             $key  The key
@param RedBlackNode|null $node The subtree root

@return int
Retrieves the rank for a key in a subtree