MCPcopy
hub / github.com/prometheus/prometheus / ApplySearchHints

Function ApplySearchHints

storage/generic.go:252–268  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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)).
252func 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

Callers 4

SearchLabelNamesMethod · 0.92
SearchLabelValuesMethod · 0.92
TestApplySearchHintsFunction · 0.85

Calls 4

applySearchHintsNoFilterFunction · 0.85
topKByScoreFunction · 0.85
reverseFilterEarlyExitFunction · 0.85
applySearchHintsLinearFunction · 0.85

Tested by 2

TestApplySearchHintsFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…