Could you give us a complete example?
Closed this issue · 1 comments
agile6v commented
As the title. Thanks.
fran6co commented
It's been a while from the last time I used PHP, but the general gist of a trie is to get O(n) complexity where n is the length of the search string instead of the amount of objects the trie contains. So, it could be used like an associative array but with a different interface (if someone has the time to create a PR it could be standarized to the array interface)
$trie = new \PHPTrie\Trie()
$trie->add("Argentina", "AR")
$trie->add("United Kingdom", "UK")
$abbreviation = $trie->search("Argentina")
Another use case is when searching multiple keys that it looks for the longest key it can find in a string
$trie = new \PHPTrie\Trie()
$trie->add("Argentina", "AR")
$trie->add("United Kingdom", "UK")
$abbreviations = $trie->search(array("A", "day", "in", "the", "United", "Kingdom"))
The interface needs a lot of improvements, feel free to contribute =D