sam/harbor — pull request #33 by fgrehm (2012-03-05 00:51:48+00:00)
Title: Router work

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](http://www.cse.ohio-state.edu/~gurari/course/cis680/cis680Ch12.html) 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](http://en.wikipedia.org/wiki/AVL_tree), 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 ;-)