MCPcopy
hub / github.com/go-chi/chi / findEdge

Method findEdge

tree.go:546–572  ·  view source on GitHub ↗
(ntyp nodeTyp, label byte)

Source from the content-addressed store, hash-verified

544}
545
546func (n *node) findEdge(ntyp nodeTyp, label byte) *node {
547 nds := n.children[ntyp]
548 num := len(nds)
549 idx := 0
550
551 switch ntyp {
552 case ntStatic, ntParam, ntRegexp:
553 i, j := 0, num-1
554 for i <= j {
555 idx = i + (j-i)/2
556 if label > nds[idx].label {
557 i = idx + 1
558 } else if label < nds[idx].label {
559 j = idx - 1
560 } else {
561 i = num // breaks cond
562 }
563 }
564 if nds[idx].label != label {
565 return nil
566 }
567 return nds[idx]
568
569 default: // catch all
570 return nds[idx]
571 }
572}
573
574func (n *node) isLeaf() bool {
575 return n.endpoints != nil

Callers 2

findRouteMethod · 0.45
findPatternMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected