Skip to content

Commit

Permalink
fix setting short/long path causes new branch node' data corrupted
Browse files Browse the repository at this point in the history
  • Loading branch information
hedzr committed Nov 13, 2024
1 parent 256f905 commit 2ed6d00
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions radix/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,25 +76,25 @@ func (s *nodeS[T]) ResetModified() {

// Data returns the Data field of a node.
func (s *nodeS[T]) Data() (data T) {
if !s.isBranch() {
data = s.data
}
// if !s.isBranch() {
data = s.data
// }
return
}

// SetData sets the Data field of a node.
func (s *nodeS[T]) SetData(data T) {
if !s.isBranch() {
s.data = data
s.nType |= NTData
}
// if !s.isBranch() {
s.data = data
s.nType |= NTData
// }
}

// SetEmpty clear the Data field.
func (s *nodeS[T]) SetEmpty() {
if !s.isBranch() {
s.nType &= ^NTData
}
// if !s.isBranch() {
s.nType &= ^NTData
// }
}

// SetComment sets the Description and Comment field.
Expand Down Expand Up @@ -185,6 +185,7 @@ func (s *nodeS[T]) insertInternal(word []rune, fullPath string, data T) (node *n
if cpl < ourLen {
// eg: insert 'apple' into 'appZ', or insert 'appZ' into 'apple'
base.split(cpl, word) // split this as 'app' and 'Z'/'le'
// eg2: insert '/app/:client/tokens' into '/app/:client/tokens/:token',
}

if cpl < wordLen {
Expand Down Expand Up @@ -236,6 +237,8 @@ func (s *nodeS[T]) split(pos int, word []rune) (newNode *nodeS[T]) { //nolint:un
s.pathS = s.pathS[:len(s.pathS)-d] // s.pathS[:pos] //
s.children = []*nodeS[T]{newNode}
s.nType = NTBranch
var t T
s.data = t
assert(strings.HasSuffix(s.pathS, string(s.path)), "parentNode: pathS(%q) should end with path(%q)", s.pathS, string(s.path))
return
}
Expand Down

0 comments on commit 2ed6d00

Please sign in to comment.