{"id":18932090,"url":"https://github.com/justjake/ruby-array-trie","last_synced_at":"2026-01-08T02:53:11.917Z","repository":{"id":62553537,"uuid":"110912116","full_name":"justjake/ruby-array-trie","owner":"justjake","description":"Trie-like, prefix-tree data structures that maps from ordered keys to values. Ruby.","archived":false,"fork":false,"pushed_at":"2017-11-16T02:56:28.000Z","size":15,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-25T19:02:22.008Z","etag":null,"topics":["array","data-structure","ruby","trie"],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/justjake.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-11-16T02:24:17.000Z","updated_at":"2021-11-05T13:29:26.000Z","dependencies_parsed_at":"2022-11-03T04:45:32.430Z","dependency_job_id":null,"html_url":"https://github.com/justjake/ruby-array-trie","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justjake%2Fruby-array-trie","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justjake%2Fruby-array-trie/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justjake%2Fruby-array-trie/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justjake%2Fruby-array-trie/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/justjake","download_url":"https://codeload.github.com/justjake/ruby-array-trie/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246334455,"owners_count":20760646,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["array","data-structure","ruby","trie"],"created_at":"2024-11-08T11:48:11.948Z","updated_at":"2026-01-08T02:53:11.871Z","avatar_url":"https://github.com/justjake.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ArrayTrie\n\n[![Ruby gem](https://img.shields.io/gem/v/array_trie.svg)](https://rubygems.org/gems/array_trie)\n[API docs](http://www.rubydoc.info/gems/array_trie)\n\nTrie-like, prefix-tree data structures. First, a prefix-tree based on Arrays, which differs from a traditional trie, which maps strings to values. Second, a more general prefix-tree data structure that works for any type of keys, provided those keys can be transformed to and from an array.\n\nBoth of these data structures are implemented in terms of hashes.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'array_trie'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install array_trie\n\n## Usage\n\nUse the base `ArrayTrie` class if you want to work with an array-keyed trie.\nThe more general `ArrayTrie::PrefixTrie` class can be used with any sort of\nordered key.\n\n```ruby\nrequire 'array_trie/prefix_trie'\n\n# You can store any sort of ordered key in a PrefixTrie, provided you can\n# convert to and from arrays in a stable way.\npath_to_a = -\u003e (path) { path.split('/') }\na_to_path = -\u003e (array) { array.join('/') }\npaths = ArrayTrie::PrefixTrie.new(path_to_a, a_to_path)\n\n# Store some keys in the trie\npaths['/usr/local/bin/ruby'] = 'executable'\npaths['/usr/local/etc/nginx/nginx.cfg'] = 'config file'\npaths['/bin/bash'] = 'executable'\n\n# Tries have efficient prefix queries\npaths.include_prefix?('/usr/local') \n# =\u003e true\npaths.count_prefix('/usr/local')\n# =\u003e 2\n\n# You can obtain a subtrie to operate on a subsection of your trie\nusr_local = paths.subtrie('/usr/local')\nusr_local['bin/ruby']\n# =\u003e \"executable\"\n\nusr_local['bin/fish'] = 'executable'\npaths['/usr/local/bin/fish']\n# =\u003e \"executable\"\n\n# Use #breadth_first and #depth_first to enumarate your keys and values\npaths.breadth_first do |k, v|\n  puts \"Path #{k} is of type #{v}\"\nend\n# STDOUT: Path /bin/bash is of type executable\n# STDOUT: Path /usr/local/bin/ruby is of type executable\n# STDOUT: Path /usr/local/etc/nginx/nginx.cfg is of type config file\n\n# These methods return Enumerators, so you can use them with #map, etc.\nenum = paths.depth_first\nas_hash = Hash[enum.to_a]\n# =\u003e  {\n# ...   \"/usr/local/bin/ruby\"=\u003e\"executable\",\n# ...   \"/usr/local/etc/nginx/nginx.cfg\"=\u003e\"config file\",\n# ...   \"/bin/bash\"=\u003e\"executable\"\n# ... }\n```\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment. Finally, use `bin/test` to run the tests.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/justjake/array_trie.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjustjake%2Fruby-array-trie","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjustjake%2Fruby-array-trie","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjustjake%2Fruby-array-trie/lists"}