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