mirror of
https://github.com/metosin/reitit.git
synced 2025-12-18 08:51:12 +00:00
:segment-router -> :trie-router
This commit is contained in:
parent
415cd7af89
commit
ce80f83319
4 changed files with 13 additions and 11 deletions
|
|
@ -5,10 +5,10 @@ Reitit ships with several different implementations for the `Router` protocol, o
|
||||||
| router | description |
|
| router | description |
|
||||||
| ------------------------------|-------------|
|
| ------------------------------|-------------|
|
||||||
| `:linear-router` | Matches the routes one-by-one starting from the top until a match is found. Slow, but works with all route trees.
|
| `:linear-router` | Matches the routes one-by-one starting from the top until a match is found. Slow, but works with all route trees.
|
||||||
| `:segment-router` | Router that creates a optimized [search trie](https://en.wikipedia.org/wiki/Trie) out of an route table. Much faster than `:linear-router` for wildcard routes. Valid only if there are no [Route conflicts](../basics/route_conflicts.md).
|
| `:trie-router` | Router that creates a optimized [search trie](https://en.wikipedia.org/wiki/Trie) out of an route table. Much faster than `:linear-router` for wildcard routes. Valid only if there are no [Route conflicts](../basics/route_conflicts.md).
|
||||||
| `:lookup-router` | Fast router, uses hash-lookup to resolve the route. Valid if no paths have path or catch-all parameters and there are no [Route conflicts](../basics/route_conflicts.md).
|
| `:lookup-router` | Fast router, uses hash-lookup to resolve the route. Valid if no paths have path or catch-all parameters and there are no [Route conflicts](../basics/route_conflicts.md).
|
||||||
| `:single-static-path-router` | Super fast router: string-matches a route. Valid only if there is one static route.
|
| `:single-static-path-router` | Super fast router: string-matches a route. Valid only if there is one static route.
|
||||||
| `:mixed-router` | Contains two routers: `:segment-router` for wildcard routes and a `:lookup-router` or `:single-static-path-router` for static routes. Valid only if there are no [Route conflicts](../basics/route_conflicts.md).
|
| `:mixed-router` | Contains two routers: `:trie-router` for wildcard routes and a `:lookup-router` or `:single-static-path-router` for static routes. Valid only if there are no [Route conflicts](../basics/route_conflicts.md).
|
||||||
| `:quarantine-router` | Contains two routers: `:mixed-router` for non-conflicting routes and a `:linear-router` for conflicting routes.
|
| `:quarantine-router` | Contains two routers: `:mixed-router` for non-conflicting routes and a `:linear-router` for conflicting routes.
|
||||||
|
|
||||||
The router name can be asked from the router:
|
The router name can be asked from the router:
|
||||||
|
|
|
||||||
|
|
@ -252,11 +252,11 @@
|
||||||
(if-let [match (impl/fast-get lookup name)]
|
(if-let [match (impl/fast-get lookup name)]
|
||||||
(match (impl/path-params path-params))))))))
|
(match (impl/path-params path-params))))))))
|
||||||
|
|
||||||
(defn segment-router
|
(defn trie-router
|
||||||
"Creates a special prefix-tree style segment router from resolved routes and optional
|
"Creates a special prefix-tree router from resolved routes and optional
|
||||||
expanded options. See [[router]] for available options."
|
expanded options. See [[router]] for available options."
|
||||||
([compiled-routes]
|
([compiled-routes]
|
||||||
(segment-router compiled-routes {}))
|
(trie-router compiled-routes {}))
|
||||||
([compiled-routes opts]
|
([compiled-routes opts]
|
||||||
(let [names (find-names compiled-routes opts)
|
(let [names (find-names compiled-routes opts)
|
||||||
[pl nl] (reduce
|
[pl nl] (reduce
|
||||||
|
|
@ -276,7 +276,7 @@
|
||||||
(reify
|
(reify
|
||||||
Router
|
Router
|
||||||
(router-name [_]
|
(router-name [_]
|
||||||
:segment-router)
|
:trie-router)
|
||||||
(routes [_]
|
(routes [_]
|
||||||
routes)
|
routes)
|
||||||
(compiled-routes [_]
|
(compiled-routes [_]
|
||||||
|
|
@ -345,7 +345,7 @@
|
||||||
([compiled-routes opts]
|
([compiled-routes opts]
|
||||||
(let [{wild true, lookup false} (group-by impl/wild-route? compiled-routes)
|
(let [{wild true, lookup false} (group-by impl/wild-route? compiled-routes)
|
||||||
->static-router (if (= 1 (count lookup)) single-static-path-router lookup-router)
|
->static-router (if (= 1 (count lookup)) single-static-path-router lookup-router)
|
||||||
wildcard-router (segment-router wild opts)
|
wildcard-router (trie-router wild opts)
|
||||||
static-router (->static-router lookup opts)
|
static-router (->static-router lookup opts)
|
||||||
names (find-names compiled-routes opts)
|
names (find-names compiled-routes opts)
|
||||||
routes (uncompile-routes compiled-routes)]
|
routes (uncompile-routes compiled-routes)]
|
||||||
|
|
@ -446,7 +446,7 @@
|
||||||
(and (= 1 (count compiled-routes)) (not wilds?)) single-static-path-router
|
(and (= 1 (count compiled-routes)) (not wilds?)) single-static-path-router
|
||||||
path-conflicting quarantine-router
|
path-conflicting quarantine-router
|
||||||
(not wilds?) lookup-router
|
(not wilds?) lookup-router
|
||||||
all-wilds? segment-router
|
all-wilds? trie-router
|
||||||
:else mixed-router)]
|
:else mixed-router)]
|
||||||
|
|
||||||
(when-let [validate (:validate opts)]
|
(when-let [validate (:validate opts)]
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,9 @@
|
||||||
(concat ss (-static from to))
|
(concat ss (-static from to))
|
||||||
(condp = (get s to)
|
(condp = (get s to)
|
||||||
\{ (let [to' (or (str/index-of s "}" to) (throw (ex-info (str "Unbalanced brackets: " (pr-str s)) {})))]
|
\{ (let [to' (or (str/index-of s "}" to) (throw (ex-info (str "Unbalanced brackets: " (pr-str s)) {})))]
|
||||||
(recur (concat ss (-static from to) (-wild to to')) (inc to') (inc to')))
|
(if (= \* (get s (inc to)))
|
||||||
|
(recur (concat ss (-static from to) (-catch-all (inc to) to')) (inc to') (inc to'))
|
||||||
|
(recur (concat ss (-static from to) (-wild to to')) (inc to') (inc to'))))
|
||||||
\: (let [to' (or (str/index-of s "/" to) (count s))]
|
\: (let [to' (or (str/index-of s "/" to) (count s))]
|
||||||
(recur (concat ss (-static from to) (-wild to to')) to' to'))
|
(recur (concat ss (-static from to) (-wild to to')) to' to'))
|
||||||
\* (let [to' (count s)]
|
\* (let [to' (count s)]
|
||||||
|
|
|
||||||
|
|
@ -103,7 +103,7 @@
|
||||||
(is (= nil (matches ""))))))
|
(is (= nil (matches ""))))))
|
||||||
|
|
||||||
r/linear-router :linear-router
|
r/linear-router :linear-router
|
||||||
r/segment-router :segment-router
|
r/trie-router :trie-router
|
||||||
r/mixed-router :mixed-router
|
r/mixed-router :mixed-router
|
||||||
r/quarantine-router :quarantine-router))
|
r/quarantine-router :quarantine-router))
|
||||||
|
|
||||||
|
|
@ -142,7 +142,7 @@
|
||||||
r/lookup-router :lookup-router
|
r/lookup-router :lookup-router
|
||||||
r/single-static-path-router :single-static-path-router
|
r/single-static-path-router :single-static-path-router
|
||||||
r/linear-router :linear-router
|
r/linear-router :linear-router
|
||||||
r/segment-router :segment-router
|
r/trie-router :trie-router
|
||||||
r/mixed-router :mixed-router
|
r/mixed-router :mixed-router
|
||||||
r/quarantine-router :quarantine-router))
|
r/quarantine-router :quarantine-router))
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue