MCPcopy Create free account
hub / github.com/devfeel/dotweb / incrementChildPrio

Method incrementChildPrio

tree.go:101–121  ·  view source on GitHub ↗

Increments priority of the given child and reorders if necessary

(pos int)

Source from the content-addressed store, hash-verified

99
100// Increments priority of the given child and reorders if necessary
101func (n *Node) incrementChildPrio(pos int) int {
102 cs := n.children
103 cs[pos].priority++
104 prio := cs[pos].priority
105
106 // Adjust position (move to front)
107 newPos := pos
108 for ; newPos > 0 && cs[newPos-1].priority < prio; newPos-- {
109 // Swap node positions
110 cs[newPos-1], cs[newPos] = cs[newPos], cs[newPos-1]
111 }
112
113 // Build new index char string
114 if newPos != pos {
115 n.indices = n.indices[:newPos] + // Unchanged prefix, might be empty
116 n.indices[pos:pos+1] + // The index char we move
117 n.indices[newPos:pos] + n.indices[pos+1:] // Rest without char at 'pos'
118 }
119
120 return newPos
121}
122
123// addRoute adds a node with the given handle to the path.
124// Not concurrency-safe!

Callers 1

addRouteMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected