trie

Trie

A trie is a data structure for efficiently storing and retrieving strings with identical prefixes, like "meet" and "meek".

Installation

  1. Add the dependency to your shard.yml:

    dependencies:
      cadmium_trie:
        github: cadmiumcr/trie
    
  2. Run shards install

Usage

require "trie"
trie = Cadmium.trie.new

trie.add("meet")
trie.size
# => 5

trie.add("meek")
trie.size
# => 6

trie.contains?("meet")
# => true

trie.find_prefix("meeting")
# => {"meet", "ing"}
trie.find_prefix("meet")
# => {"meet", ""}
trie.find_prefix("me")
# => {nil, "me"}

trie.keys_with_prefix("me")
# => ["meet", "meek"]

trie.add(["m", "me"])
trie.matches_on_path("meeting")
# => ["m", "me", "meet"]

Contributing

  1. Fork it (https://github.com/cadmiumcr/trie/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

Repository

trie

Owner
Statistic
  • 1
  • 1
  • 0
  • 1
  • 0
  • over 5 years ago
  • August 28, 2019
License

MIT License

Links
Synced at

Sat, 21 Dec 2024 04:16:23 GMT

Languages