Skip to content

Commit

Permalink
Improve complexity of getting all fingerprints
Browse files Browse the repository at this point in the history
  • Loading branch information
taisho6339 committed Oct 29, 2021
1 parent 5b48e51 commit cc1c677
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions pkg/ingester/index/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,16 +319,24 @@ func (shard *indexShard) allFPs() model.Fingerprints {
shard.mtx.RLock()
defer shard.mtx.RUnlock()

var result model.Fingerprints
var fps model.Fingerprints
for _, ie := range shard.idx {
for _, ive := range ie.fps {
result = intersect(result, ive.fps)
fps = append(fps, ive.fps...)
}
sort.Sort(result)
}
if len(result) == 0 {
if len(fps) == 0 {
return nil
}

var result model.Fingerprints
var m = map[model.Fingerprint]struct{}{}
for _, fp := range fps {
if _, ok := m[fp]; !ok {
m[fp] = struct{}{}
result = append(result, fp)
}
}
return result
}

Expand Down

0 comments on commit cc1c677

Please sign in to comment.