Skip to content

Commit

Permalink
improved endsWith
Browse files Browse the repository at this point in the history
  • Loading branch information
hedzr committed Nov 14, 2024
1 parent f8c2492 commit 4b6de85
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
21 changes: 10 additions & 11 deletions radix/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,22 +123,24 @@ func (s *nodeS[T]) StartsWith(ch rune) bool { //nolint:revive
}

func (s *nodeS[T]) EndsWith(ch rune) bool { //nolint:revive
if len(s.path) == 0 {
kl := len(s.path)
if kl == 0 {
return false
}
return s.path[len(s.path)-1] == ch
return s.path[kl-1] == ch
}

func (s *nodeS[T]) endsWith(ch rune) bool { //nolint:revive
if len(s.path) == 0 {
kl := len(s.path)
if kl == 0 {
return false
}
return s.path[len(s.path)-1] == ch
return s.path[kl-1] == ch
}

func (s *nodeS[T]) endsWithLite(ch rune) bool { //nolint:revive,unused
return s.path[len(s.path)-1] == ch
}
// func (s *nodeS[T]) endsWithLite(ch rune) bool { //nolint:revive,unused
// return s.path[len(s.path)-1] == ch
// }

func (s *nodeS[T]) remove(item *nodeS[T]) (removed bool) { //nolint:revive
if item == nil {
Expand Down Expand Up @@ -290,10 +292,7 @@ func (s *nodeS[T]) matchR(word []rune, delimiter rune, dm bool, parentNode *node

// dm: delimiter just matched?
// mptr: the working node ptr
mptr, dm, srcMatchedL, dstMatchedL, minL, maxL := s, false, 0, 0, min(l, wl), max(l, wl)
if parentNode != nil {
dm = parentNode.endsWith(delimiter)
}
mptr, srcMatchedL, dstMatchedL, minL, maxL := s, 0, 0, min(l, wl), max(l, wl)
masterLoop:
for ; srcMatchedL < minL; srcMatchedL++ {
ch := mptr.path[srcMatchedL]
Expand Down
6 changes: 3 additions & 3 deletions radix/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ func TestNodeS_Tag(t *testing.T) {
if node.endsWith('.') {
t.Fail()
}
if node.endsWithLite('.') {
t.Fail()
}
// if node.endsWithLite('.') {
// t.Fail()
// }

assert(!node.IsLeaf())
assert(!node.HasData())
Expand Down

0 comments on commit 4b6de85

Please sign in to comment.