{"id":18011704,"url":"https://github.com/renatoathaydes/pathtrie","last_synced_at":"2025-04-04T13:43:47.764Z","repository":{"id":138193540,"uuid":"134728766","full_name":"renatoathaydes/pathtrie","owner":"renatoathaydes","description":"A Trie implementation specifically designed for paths","archived":false,"fork":false,"pushed_at":"2018-10-02T18:24:18.000Z","size":86,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-09T23:28:26.972Z","etag":null,"topics":["data-structures","java","routing","trie"],"latest_commit_sha":null,"homepage":null,"language":"Java","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/renatoathaydes.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-05-24T14:42:11.000Z","updated_at":"2023-04-12T07:00:37.000Z","dependencies_parsed_at":null,"dependency_job_id":"1a25986d-5622-4bd9-8b62-f2d33d1ba056","html_url":"https://github.com/renatoathaydes/pathtrie","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renatoathaydes%2Fpathtrie","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renatoathaydes%2Fpathtrie/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renatoathaydes%2Fpathtrie/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renatoathaydes%2Fpathtrie/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/renatoathaydes","download_url":"https://codeload.github.com/renatoathaydes/pathtrie/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247189504,"owners_count":20898691,"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-structures","java","routing","trie"],"created_at":"2024-10-30T03:12:31.418Z","updated_at":"2025-04-04T13:43:47.744Z","avatar_url":"https://github.com/renatoathaydes.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PathTrie\n\nA [Trie](https://en.wikipedia.org/wiki/Trie) implementation designed specifically for using paths as keys.\n\nThe main use of this data structure is to locate information stored under hierarchical paths, such as files and URLs,\nvery fast.\n\n## Simple Usage\n\nThe main type of this library is `com.athaydes.pathtrie.PathTrie`.\n\nTo create a new `PathTrie`, a builder is used:\n\n```java\nvar trie = PathTrie.\u003cInteger\u003enewBuilder()\n    .put(\"/hello/world\", 1)\n    .put(\"/other/path\", 2)\n    .build();\n```\n\nRetrieving a value from a `PathTrie`:\n\n```java\nOptional\u003cInteger\u003e value = trie.get(\"/hello/world\");\n\nassertTrue(value.isPresent());\nassertEquals(Integer.valueOf(1), value.get());\n```\n\nYou can also retrieve a sub-trie:\n\n```java\nOptional\u003cPathTrie\u003cInteger\u003e\u003e helloTrie = trie.getChild(\"/hello\");\n\nassertTrue(helloTrie.isPresent());\nassertEquals(Integer.valueOf(1), helloTrie.get().get(\"world\").get());\n```\n\n## Parameterized Usage\n\n`PathTrie` also supports parameterized mappings:\n\n```java\nfinal Map\u003cString, String\u003e users = new LinkedHashMap\u003c\u003e();\nusers.put(\"123\", \"Joe\");\nusers.put(\"456\", \"Mary\");\n\nPathTrie\u003cObject\u003e parameterizedTrie = PathTrie.newBuilder()\n    .putFun(\"/users\", () -\u003e users)\n    .putFun(\"/users/:id\", id -\u003e users.get(id))\n    .build();\n\nassertEquals(users, parameterizedTrie.get(\"/users\").orElse(emptyMap()));\nassertEquals(\"Joe\", parameterizedTrie.get(\"/users/123\").orElse(\"NOT FOUND\"));\nassertEquals(\"Mary\", parameterizedTrie.get(\"/users/456\").orElse(\"NOT FOUND\"));\n\nassertFalse(parameterizedTrie.get(\"/others\").isPresent());\nassertFalse(parameterizedTrie.get(\"/users/789\").isPresent());\n```\n\nUp to 4 parameters can be used (if more is needed, you can implement `com.athaydes.pathtrie.functions.Fun` providing\nan adapter that can take more parameters):\n\n```java\nPathTrie\u003cObject\u003e parameterizedTrie = PathTrie.newBuilder()\n    .putFun(\"/:a/:b/:c/:d\", (a, b, c, d) -\u003e \"a=\" + a + \",b=\" + b + \",c=\" + c + \",d=\" + d)\n    .build();\n\nassertEquals(\"a=A,b=B,c=C,d=D\", parameterizedTrie.get(\"/A/B/C/D\").orElse(\"NOT FOUND\"));\n```\n\nNotice that the lambda arguments are positional (i.e. their names don't matter, only their positions relative to the\npath).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frenatoathaydes%2Fpathtrie","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frenatoathaydes%2Fpathtrie","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frenatoathaydes%2Fpathtrie/lists"}