{"id":20441393,"url":"https://github.com/sandromaglione/itrie","last_synced_at":"2025-04-12T23:22:28.558Z","repository":{"id":216702733,"uuid":"742085542","full_name":"SandroMaglione/itrie","owner":"SandroMaglione","description":"Efficient, immutable and stack safe implementation of a Trie data structure in dart: autocomplete, text search, spell checking, strings and prefixes","archived":false,"fork":false,"pushed_at":"2024-01-22T04:59:48.000Z","size":2933,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-26T17:21:27.180Z","etag":null,"topics":["data-structure","immutable","immutable-dart","immutable-datastructures","trie","trie-dart","trie-data-structure","trie-immutable","trie-implementation","trie-structure"],"latest_commit_sha":null,"homepage":"https://pub.dev/packages/itrie","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SandroMaglione.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-01-11T18:23:33.000Z","updated_at":"2024-12-04T01:43:50.000Z","dependencies_parsed_at":"2024-01-12T05:13:13.944Z","dependency_job_id":"17097ad1-1a79-499f-a0db-082fd9812e62","html_url":"https://github.com/SandroMaglione/itrie","commit_stats":null,"previous_names":["sandromaglione/itrie"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SandroMaglione%2Fitrie","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SandroMaglione%2Fitrie/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SandroMaglione%2Fitrie/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SandroMaglione%2Fitrie/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SandroMaglione","download_url":"https://codeload.github.com/SandroMaglione/itrie/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248644213,"owners_count":21138570,"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":["data-structure","immutable","immutable-dart","immutable-datastructures","trie","trie-dart","trie-data-structure","trie-immutable","trie-implementation","trie-structure"],"created_at":"2024-11-15T09:32:34.612Z","updated_at":"2025-04-12T23:22:28.538Z","avatar_url":"https://github.com/SandroMaglione.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1\u003eITrie\u003c/h1\u003e\n\n\u003cp\u003e\n    \u003ca href=\"https://github.com/SandroMaglione/itrie\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/stars/SandroMaglione/itrie?logo=github\" /\u003e\n    \u003c/a\u003e\n    \u003c!-- \u003cimg src=\"https://img.shields.io/pub/v/fpdart?include_prereleases\" /\u003e --\u003e\n    \u003cimg src=\"https://img.shields.io/github/license/SandroMaglione/itrie?logo=github\" /\u003e\n    \u003ca href=\"https://github.com/SandroMaglione\"\u003e\n    \u003cimg alt=\"GitHub: SandroMaglione\" src=\"https://img.shields.io/github/followers/SandroMaglione?label=Follow\u0026style=social\" target=\"_blank\" /\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://twitter.com/SandroMaglione\"\u003e\n    \u003cimg alt=\"Twitter: SandroMaglione\" src=\"https://img.shields.io/twitter/follow/SandroMaglione.svg?style=social\" target=\"_blank\" /\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n\n**Efficient, immutable and stack safe** implementation of a `Trie` data structure in dart.\n\n`Trie` is ideal for **autocomplete**, **text search**, **spell checking**, and generally when working with string and prefixes.\n\n- [💻 Installation](#-installation)\n- [💡 How to use](#-how-to-use)\n  - [Constructors](#constructors)\n  - [`Iterable`](#iterable)\n  - [Mutations (Immutable)](#mutations-immutable)\n  - [Getters](#getters)\n- [🛠️ Properties](#️-properties)\n  - [Immutable](#immutable)\n  - [Stack safe](#stack-safe)\n  - [(Space) Efficient](#space-efficient)\n- [📃 Versioning](#-versioning)\n- [😀 Support](#-support)\n- [👀 License](#-license)\n\n\n\n## 💻 Installation\n\n```yaml\n# pubspec.yaml\ndependencies:\n  itrie: ^0.0.2\n```\n\n## 💡 How to use\nThe package export a single `ITrie` class.\n\n### Constructors\nAn `ITrie` can be created from any `Iterable` or using the `empty` constructor:\n\n```dart\n/// Empty [ITrie] with [int] values\nfinal empty = ITrie\u003cint\u003e.empty();\nfinal copy = empty.insert(\"key\", 10);\n\n/// From [Iterable] containing a record of `(String, T)`\nfinal fromIterable = ITrie.fromIterable([(\"key\", 10)]);\n```\n\n### `Iterable`\n`ITrie` extends `Iterable`.\n\nThis means that you have access to all the methods\navailable in the [Iterable API](https://api.dart.dev/stable/3.2.5/dart-core/Iterable-class.html#instance-methods):\n- [`map`](https://api.dart.dev/stable/3.2.5/dart-core/Iterable/map.html)\n- [`fold`](https://api.dart.dev/stable/3.2.5/dart-core/Iterable/fold.html)\n- [`every`](https://api.dart.dev/stable/3.2.5/dart-core/Iterable/every.html)\n- [`iterator`](https://api.dart.dev/stable/3.2.5/dart-core/Iterable/iterator.html)\n- And more 🚀\n\n### Mutations (Immutable)\nMethods to add/remove/modify key/value inside `ITrie`:\n\n```dart\nfinal itrie = ITrie\u003cint\u003e.empty();\n\nfinal insert = itrie.insert(\"key\", 10);\nfinal remove = itrie.remove(\"key\");\nfinal modify = itrie.modify(\"key\", (value) =\u003e value + 1);\nfinal insertMany = itrie.insertMany([(\"key2\", 20)]);\nfinal removeMany = itrie.removeMany([\"key\"]);\n```\n\n\u003e 🧱 `ITrie` **is immutable**\n\u003e \n\u003e These methods return a new copy of the original `ITrie`\n\u003e **without modifying the original** `ITrie`\n\n### Getters\nMethods to extract key/value based on `key` and `prefix`:\n\n```dart\nfinal itrie = ITrie\u003cint\u003e.empty();\n\nfinal getV = itrie.get(\"key\");\nfinal longestPrefixOf = itrie.longestPrefixOf(\"keys\");\nfinal withPrefix = itrie.withPrefix(\"ke\");\nfinal keysWithPrefix = itrie.keysWithPrefix(\"ke\");\nfinal valuesWithPrefix = itrie.valuesWithPrefix(\"ke\");\nfinal keys = itrie.keys;\nfinal values = itrie.values;\nfinal length = itrie.length;\nfinal has = itrie.has(\"key\");\n```\n\n## 🛠️ Properties\n\n### Immutable\nThe main difference between other trie implementations is that `ITrie` is **immutable**.\n\nEvery mutation (e.g. `insert`, `delete`, `modify`) returns a new instance of `ITrie` instead of modifying the original `ITrie` in-place.\n\n```dart\nfinal itrie = ITrie\u003cint\u003e.empty();\nfinal newITrie = itrie.insert(\"key\", 10); /// 👈 `insert` returns a new [ITrie]\n\nexpect(itrie.length, 0); /// 👈 Original `itrie` is not modified\nexpect(newITrie.length, 1);\n```\n\n\u003e ✅ Immutability in `ITrie` uses a technique called **Path copying**: this makes `ITrie` efficient since it does not require to copy the full data structure with every mutation \n\n### Stack safe\n`ITrie` does **not** use recursion. No matter how many operations or elements it contains, `ITrie` will never cause stack overflow issues.\n\n### (Space) Efficient\n`ITrie` is implemented internally as a **Ternary Search Trie**. This data structure allows for any alphabet size (any `String`) and it is also more space efficient compared to other trie implementations.\n\n\n***\n\n\n## 📃 Versioning\n\n- v0.0.2 - 22 January 2024\n- v0.0.1 - 22 January 2024\n\n## 😀 Support\n\nIf you are interested in my work you can [**subscribe to my newsletter**](https://www.sandromaglione.com/newsletter). \n\nFor more frequent updates you can also follow me on my [**Twitter**](https://twitter.com/SandroMaglione).\n\n## 👀 License\n\nMIT License, see the [LICENSE.md](https://github.com/SandroMaglione/itrie/blob/main/LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsandromaglione%2Fitrie","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsandromaglione%2Fitrie","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsandromaglione%2Fitrie/lists"}