github.com/yankunsam/loki/v2@v2.6.3-0.20220817130409-389df5235c27/pkg/storage/stores/tsdb/index/fingerprint.go (about)

     1  package index
     2  
     3  import (
     4  	"math"
     5  	"sort"
     6  )
     7  
     8  // (SeriesRef, Fingerprint) tuples
     9  type FingerprintOffsets [][2]uint64
    10  
    11  func (xs FingerprintOffsets) Range(shard ShardAnnotation) (minOffset, maxOffset uint64) {
    12  	from, through := shard.Bounds()
    13  	lower := sort.Search(len(xs), func(i int) bool {
    14  		return xs[i][1] >= uint64(from)
    15  	})
    16  
    17  	if lower < len(xs) && lower > 0 {
    18  		// If lower is the first series offset
    19  		// to exist in this shard, we must also check
    20  		// any offsets since the previous sample as well
    21  		minOffset = xs[lower-1][0]
    22  	}
    23  
    24  	upper := sort.Search(len(xs), func(i int) bool {
    25  		return xs[i][1] >= uint64(through)
    26  	})
    27  
    28  	// If there are no sampled fingerprints greater than this shard,
    29  	// we must check to the end of TSDB series offsets.
    30  	if upper == len(xs) {
    31  		maxOffset = math.MaxUint64
    32  	} else {
    33  		maxOffset = xs[upper][0]
    34  	}
    35  
    36  	return
    37  }