{"id":17979090,"url":"https://github.com/sidvishnoi/compact-prefix-tree","last_synced_at":"2025-05-06T21:10:01.843Z","repository":{"id":119737684,"uuid":"162345951","full_name":"sidvishnoi/compact-prefix-tree","owner":"sidvishnoi","description":"A serializable compact prefix tree (also known as Radix tree or Patricia tree or space-optimized trie) implementation in JavaScript.","archived":false,"fork":false,"pushed_at":"2019-10-08T13:49:24.000Z","size":8,"stargazers_count":4,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-06T21:09:51.753Z","etag":null,"topics":["compact-prefix-tree","data-structures","patricia-tree","prefix-tree","prefix-trie","radix-tree","trie","trie-tree"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/sidvishnoi.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-12-18T21:13:48.000Z","updated_at":"2024-04-12T11:01:17.000Z","dependencies_parsed_at":"2023-07-18T01:01:19.573Z","dependency_job_id":null,"html_url":"https://github.com/sidvishnoi/compact-prefix-tree","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sidvishnoi%2Fcompact-prefix-tree","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sidvishnoi%2Fcompact-prefix-tree/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sidvishnoi%2Fcompact-prefix-tree/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sidvishnoi%2Fcompact-prefix-tree/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sidvishnoi","download_url":"https://codeload.github.com/sidvishnoi/compact-prefix-tree/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252769425,"owners_count":21801378,"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":["compact-prefix-tree","data-structures","patricia-tree","prefix-tree","prefix-trie","radix-tree","trie","trie-tree"],"created_at":"2024-10-29T17:36:21.178Z","updated_at":"2025-05-06T21:10:01.822Z","avatar_url":"https://github.com/sidvishnoi.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Compact Prefix Tree\n\nA serializable compact prefix tree (also known as Radix tree or Patricia tree or space-optimized trie) implementation in JavaScript.\n\n## Usage\n\n### Installation\n\n``` bash\nnpm install compact-prefix-tree\n```\n\n### General Usage\n\n``` js\nimport { CompactPrefixTree } from \"compact-prefix-tree/index.js\";\n// OR\nconst { CompactPrefixTree } = require(\"compact-prefix-tree/cjs\");\n\nconst items = [\n  \"http://www.example.com/foo/\",\n  \"http://www.example.com/baz/\",\n];\n\n// create a trie from array of strings\nconst trie = new CompactPrefixTree(items);\n// can add items later\ntrie.add(\"http://www.example.com/john/\");\n\n// look for a prefix of a word\nconst p1 = trie.prefix(\"http://www.example.com/john/doe\");\n// p1: { prefix: \"http://www.example.com/john/\", isProper: true }\nconst p2 = trie.prefix(\"http://www.example.com/bazinga\");\n// p2: { prefix: \"http://www.example.com/\", isProper: false }\n// above is not proper as it doesn't exist in list of items provided\n```\n\n### Serialization\n\n``` js\nconst { CompactPrefixTree, getWordsFromTrie } = require(\"compact-prefix-tree\");\nconst items = [\n  \"http://www.example.com/foo/\",\n  \"https://www.example.com/baz/\",\n];\nconst trie = new CompactPrefixTree(items);\nconst serialized = JSON.stringify(trie.T);\n// {\n//   \"http\": {\n//     \"://www.example.com/foo/\": null,\n//     \"s://www.example.com/baz/\": null\n//   }\n// }\n\nconst words = getWordsFromTrie(JSON.parse(serialized));\n// Set(2) {\"http://www.example.com/foo/\" \"https://www.example.com/baz/\"}\n\nconst trie2 = new CompactPrefixTree(Array.from(words));\n// assert(isEqual(trie.items, trie2.items));\n```\n\n## License\n\n[MIT License] Copyright 2018 Sid Vishnoi (https://sidvishnoi.github.io)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsidvishnoi%2Fcompact-prefix-tree","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsidvishnoi%2Fcompact-prefix-tree","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsidvishnoi%2Fcompact-prefix-tree/lists"}