{"action":"opened","issue":{"url":"https://api.github.com/repos/tyler/trie/issues/18","labels_url":"https://api.github.com/repos/tyler/trie/issues/18/labels{/name}","comments_url":"https://api.github.com/repos/tyler/trie/issues/18/comments","events_url":"https://api.github.com/repos/tyler/trie/issues/18/events","html_url":"https://github.com/tyler/trie/issues/18","id":66466199,"number":18,"title":"Implement `#size` and `#length` for `Trie` and `TrieNode`","user":{"login":"roryokane","id":79168,"avatar_url":"https://avatars.githubusercontent.com/u/79168?v=3","gravatar_id":"","url":"https://api.github.com/users/roryokane","html_url":"https://github.com/roryokane","followers_url":"https://api.github.com/users/roryokane/followers","following_url":"https://api.github.com/users/roryokane/following{/other_user}","gists_url":"https://api.github.com/users/roryokane/gists{/gist_id}","starred_url":"https://api.github.com/users/roryokane/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/roryokane/subscriptions","organizations_url":"https://api.github.com/users/roryokane/orgs","repos_url":"https://api.github.com/users/roryokane/repos","events_url":"https://api.github.com/users/roryokane/events{/privacy}","received_events_url":"https://api.github.com/users/roryokane/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-04-05T18:12:32Z","updated_at":"2015-04-05T18:12:32Z","closed_at":null,"body":"I would like to be able to count how many keys are in a trie, or how many are under a certain `TrieNode`. That is, `Trie` and `TrieNode` should implement the `#size` method and its alias `#length`. Their meanings should be the same as those methods in `Hash`.\r\n\r\nWithout this functionality, I cannot use this library to implement the word game GHOST, where I try to estimate how good certain moves are by counting how many words start with a certain prefix.\r\n\r\nYou can implement this by storing an integer in every node including the root. It is initialized to 0, incremented by `#add`, and decremented by `#delete`. The methods on `Trie` would just return the size of the `#root` node.\r\n\r\nAdding the bookkeeping of key-counting will probably make the library slightly slower. If this is a big problem, you can provide two trie classes with your library: a `SimpleTrie` and a `Trie`, where a `Trie` provides more methods, but is slightly slower."}}