From 228ba2c366cd1c2e2462a8a370d78ee4b0ce3b6d Mon Sep 17 00:00:00 2001 From: Whuichenggong <147113943+Whuichenggong@users.noreply.github.com> Date: Fri, 22 Nov 2024 08:42:44 +0800 Subject: [PATCH] fix insert function --- gee-web/day3-router/gee/trie.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/gee-web/day3-router/gee/trie.go b/gee-web/day3-router/gee/trie.go index 043775c..2773673 100644 --- a/gee-web/day3-router/gee/trie.go +++ b/gee-web/day3-router/gee/trie.go @@ -21,12 +21,14 @@ func (n *node) insert(pattern string, parts []string, height int) { n.pattern = pattern return } - part := parts[height] - child := n.matchChild(part) - if child == nil { + children := n.matchChildren(part) + var child *node + if len(children) == 0 { child = &node{part: part, isWild: part[0] == ':' || part[0] == '*'} n.children = append(n.children, child) + } else { + child = children[0] // 假设我们总是取第一个匹配的子节点 } child.insert(pattern, parts, height+1) }