perf: Use swap deletion

main
CodeMarker 2026-02-06 10:49:05 +08:00 committed by begoniezhao
parent 6beb9685fc
commit 6a4a191318
1 changed files with 6 additions and 3 deletions

View File

@ -687,9 +687,12 @@ func (t *GrepChunksTool) applyMMR(
selected = append(selected, candidates[bestIdx])
selectedTokenSets = append(selectedTokenSets, tokenSets[bestIdx])
candidates = append(candidates[:bestIdx], candidates[bestIdx+1:]...)
// Remove corresponding token set
tokenSets = append(tokenSets[:bestIdx], tokenSets[bestIdx+1:]...)
// Remove corresponding token set. Use swap deletion
last := len(candidates) - 1
candidates[bestIdx] = candidates[last]
tokenSets[bestIdx] = tokenSets[last]
candidates = candidates[:last]
tokenSets = tokenSets[:last]
}
// Compute average redundancy among selected results