https://github.com/brecert/simple_trie
a very simple trie datastructure, primarily made to be used for routing tools
https://github.com/brecert/simple_trie
datastructure deno javascript
Last synced: 2 months ago
JSON representation
a very simple trie datastructure, primarily made to be used for routing tools
- Host: GitHub
- URL: https://github.com/brecert/simple_trie
- Owner: brecert
- Created: 2020-05-15T04:42:46.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-05-15T06:03:52.000Z (about 6 years ago)
- Last Synced: 2025-11-14T12:02:19.299Z (8 months ago)
- Topics: datastructure, deno, javascript
- Language: TypeScript
- Homepage:
- Size: 2.93 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# Simple Trie
This module provides a very simple trie datastructure, primarily made to be used for routing tools.
# Example
```ts
import Trie from 'https://raw.githubusercontent.com/brecert/simple_trie/master/trie.ts'
const trie = new Trie()
trie.add("/index.html", "Hello World!")
trie.add("/lib/cat.js", "cat cat cat!")
trie.add("/lib/dog.js", "dog dog dog!")
trie.add("/test/*", "test!")
trie.add("/test/*/yes", "yes")
trie.add("/test/bree", "bree")
trie.get("/index.html")
// => returns { value: "Hello World!", params: [], node: Trie }
trie.get("/lib/cat.js")
// => returns { value: "cat cat cat!", params: [], node: Trie }
trie.get("/lib/dog.js")
// => returns { value: "dog dog dog!", params: [], node: Trie }
trie.get("/test/hi")
// => returns { value: "test!", params: ["hi"], node: Trie }
trie.get("/test/hi/yes")
// => returns { value: "yes", params: ["hi"], node: Trie }
trie.get("/test/bree")
// => returns { value: "bree", params: [], node: Trie }
trie.get("/test/e/f")
// => returns { value: undefined, params: [], node: undefined }
```