ApplySearchHints filters, sorts, and limits a slice of string values according to hints, returning scored SearchResult entries. A nil hints value is treated as the zero value. The input values slice is assumed to be ordered ascending by value; the function only performs extra work for orderings that
(values []string, hints *SearchHints)
| 250 | // - Other combinations fall back to filter-then-reorder-then-slice, with the upfront |
| 251 | // capacity capped by min(len(values), max(2*Limit, minLinearAllocCap)). |
| 252 | func ApplySearchHints(values []string, hints *SearchHints) []SearchResult { |
| 253 | if hints == nil { |
| 254 | hints = &SearchHints{} |
| 255 | } |
| 256 | if hints.Filter == nil { |
| 257 | return applySearchHintsNoFilter(values, hints) |
| 258 | } |
| 259 | if hints.Limit > 0 { |
| 260 | switch hints.OrderBy { |
| 261 | case OrderByScoreDesc: |
| 262 | return topKByScore(values, hints.Filter, hints.Limit) |
| 263 | case OrderByValueDesc: |
| 264 | return reverseFilterEarlyExit(values, hints.Filter, hints.Limit) |
| 265 | } |
| 266 | } |
| 267 | return applySearchHintsLinear(values, hints) |
| 268 | } |
| 269 | |
| 270 | // reverseFilterEarlyExit walks the input ascending-sorted slice from the tail, |
| 271 | // accepting up to limit matches. Because the input is ascending, the tail |
searching dependent graphs…