MCPcopy Create free account
hub / github.com/cortexproject/cortex / sliceHistograms

Function sliceHistograms

pkg/querier/tripperware/merge.go:409–423  ·  view source on GitHub ↗

sliceHistograms assumes given histogram are sorted by timestamp in ascending order and return a sub slice whose first element's is the smallest timestamp that is strictly bigger than the given minTs. Empty slice is returned if minTs is bigger than all the timestamps in histogram.

(histograms []SampleHistogramPair, minTs int64)

Source from the content-addressed store, hash-verified

407// bigger than the given minTs. Empty slice is returned if minTs is bigger than all the
408// timestamps in histogram.
409func sliceHistograms(histograms []SampleHistogramPair, minTs int64) []SampleHistogramPair {
410 if len(histograms) <= 0 || minTs < histograms[0].GetTimestampMs() {
411 return histograms
412 }
413
414 if len(histograms) > 0 && minTs > histograms[len(histograms)-1].GetTimestampMs() {
415 return histograms[len(histograms):]
416 }
417
418 searchResult := sort.Search(len(histograms), func(i int) bool {
419 return histograms[i].GetTimestampMs() > minTs
420 })
421
422 return histograms[searchResult:]
423}

Callers 2

mergeSampleStreamsFunction · 0.85
TestSliceHistogramsFunction · 0.85

Calls 1

GetTimestampMsMethod · 0.45

Tested by 1

TestSliceHistogramsFunction · 0.68