3 ms·
This is one of the reasons for why I call it a "bastardized radix tree" in the README :) The routes are stored as "nodes". There's a root node. It has a hash m
by augustl 12y ago
This is one of the reasons for why I call it a "bastardized radix tree" in the README :)
The routes are stored as "nodes". There's a root node. It has a hash map of child nodes, by name. It also has a list of "parameterized" nodes. When a node gets a path segment, it will first look in its hash map. If nothing is there, it'll call the parameterized nodes in sequence. Typically there's just one parameterized node.
For the following paths:
/projects
/projects/new
/projects/special
/projects/:project-id
The root node will have a single item in its hash map, "projects". No items in the parameterized node.
The node for "projects" will have to items in its hash map, "new" and "special". It will have a single item in it's parameterized node, for :project-id.
I updated the README just now with a slightly more detailed explanation :)
- kyllo 12y agoVery cool, thanks for taking the time to explain! I recently learned how tries work so it was cool to see a real-world implementation like yours.