sam / harbor

Harbor is a Ruby Web Framework.
https://github.com/sam/harbor
MIT License
3 stars 6 forks source link

Optimize router tree #43

Closed fgrehm closed 12 years ago

fgrehm commented 12 years ago

The tree might get unbalanced depending on the order that routes are defined, for instance, a controller like this:

get "posts"
get "comments"
get "authors"

Will currently end up with a tree like this one:

             posts
             /
    comments
      /
authors

Which will not be optimal like this one:

    comments
      /      \
authors     posts

I was talking with @sam and another thing that we could consider is getting static routes on a Hash and leave the tree with just dynamic stuff, but we might as well have a scenario like the above with dynamic routes.

I'll give a shot at implementing an AVL at insertion time to see how it goes.

sam commented 12 years ago

Did this include the Hash for non-wildcard-routes or should that be another ticket?

fgrehm commented 12 years ago

@sam my last pull request handles the Hash, no need for new ticket ;-)

sam commented 12 years ago

Silly me, that was already done. Awesome work @fgrehm!