Updated some comments

This commit is contained in:
Sky Johnson 2025-02-15 09:02:48 -06:00
parent 872fd98c14
commit 1bd1a884c4
2 changed files with 6 additions and 7 deletions

View File

@ -21,8 +21,8 @@ router.Add("GET", "/hello", "...")
router.Add("GET", "/world", "...")
// Parameter routes
router.Add("GET", "/users/:id", "...")
router.Add("GET", "/users/:id/comments", "...")
router.Add("GET", "/users/[id]", "...")
router.Add("GET", "/users/[id]/comments", "...")
// Wildcard routes
router.Add("GET", "/images/*path", "...")

View File

@ -1,13 +1,12 @@
package router
// Super-fancy radix tree
// Representation of a node tree
type Tree[T any] struct {
root Node[T]
}
// Adds a new element to the tree
// Adds a new path to the tree
func (tree *Tree[T]) Add(path string, data T) {
// Search tree for equal parts until we can no longer proceed
i := 0
offset := 0
node := &tree.root
@ -17,8 +16,8 @@ func (tree *Tree[T]) Add(path string, data T) {
switch node.kind {
case parameter:
// This only occurs when the same parameter based route is added twice.
// node: /post/:id|
// path: /post/:id|
// node: /post/[id|
// path: /post/[id|
if i == len(path) {
node.data = data
return