Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Router work #33

Merged
merged 10 commits into from
Mar 5, 2012
Merged

Router work #33

merged 10 commits into from
Mar 5, 2012

Conversation

fgrehm
Copy link

@fgrehm fgrehm commented Mar 5, 2012

I took the challenge of getting the router to work and here it is fully functional \o/

It's basically the ternary search tree that @sam started apart for 2 scenarios:

  • The application root route / home page is not on the full router tree, the idea is to remove the overhead of dealing with previously defined routes when this one gets added and also simplify its matching (which is just a matter of checking if request path tokens are blank)
  • When there is a "conflict" between a exact token match and wildcard one, the node is extended with Habor::Router::WilcardRoute behavior (something like a multiway tree i think) which will try to perform exact matches and fail back to wildcard routes if it fails. Here's what happens under the hood when posts/:id/comments and posts/:id/tags get added after posts/archive/:author has been parsed:
posts
   |
archive
   |
:author

... add "posts/:id/comments" and "posts/:id/tags" ....

                      posts
                        |
         @wildcard_tree    @trees['archive']    <= this is a single "node"
           |                           |
          :id                       archive
           |                           |
         comments                   author
                 \
                 tags

I'm also planning to give a shot at optimizing the routing tree by making it balanced using same idea from AVL trees, I'm just not sure whether it should be at insertion or boot time. What do you guys think?

BTW, this should close #22 as well ;-)

@sam
Copy link
Owner

sam commented Mar 5, 2012

Not having a CS background, I've never seen a Multiway Tree. Algorithms are neat. :-)

Awesome work BTW.

I was thinking earlier of putting a Hash in front of the TSTree for static routes (routes with no wildcards). That would handle root, /session/new, /foo/bar/index, etc. I mean, it's not going to get faster than a simple Hash lookup right (at least I assume so)? And that might end up being half the routes in a given application...

Maybe something to toy with later anyways.

sam added a commit that referenced this pull request Mar 5, 2012
@sam sam merged commit 599965d into sam:master Mar 5, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Harbor::Router should support "/" as a valid route
2 participants