src/Datastructure/Graph/Tree/Trie/Trie.php
private function _countWords(?Node $node): int {
        $result = 0;
        if (null === $node) return $result;
        if ($node->isEndOfWordNode()) $result++;
        for ($i = 0; $i < self::ALPHABET_SIZE; $i++) {
            if ($node->hasChild($i)) {
                $child = $node->getChildNode($i);
                $result += $this->_countWords($child);
            }
        }
        return $result;
    }
private function _countWords(?Node $node): int {
        $result = 0;
        if (null === $node) return $result;
        if ($node->isEndOfWordNode()) $result++;
        for ($i = 0; $i < self::ALPHABET_SIZE; $i++) {
            if ($node->hasChild($i)) {
                $child = $node->getChildNode($i);
                $result += $this->_countWords($child);
            }
        }
        return $result;
    }
private function _countWords ( ? Node $ node ) : int { $ result = 0 ; if ( null === $ node ) return $ result ; if ( $ node -> isEndOfWordNode ( ) ) $ result ++ ; for ( $ i = 0 ; $ i < self :: ALPHABET_SIZE ; $ i ++ ) { if ( $ node -> hasChild ( $ i ) ) { $ child = $ node -> getChildNode ( $ i ) ; $ result += $ this -> _countWords ( $ child ) ; } } return $ result ; }
helper method for counting number of words in the trie

@param Node $node
@return int
helper method for counting number of words in the trie