Skip to content

Commit

Permalink
skip already processed rings
Browse files Browse the repository at this point in the history
PDOK-16135
  • Loading branch information
roelarents committed Feb 15, 2024
1 parent 3a772a4 commit 2e31eef
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions snap/snap.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,17 @@ func dedupeInnersOuters(outers [][][2]float64, inners [][][2]float64) ([][][2]fl
lenOuters := len(outers)
lenInners := len(inners)
lenAll := lenOuters + lenInners
indexesToDelete := make(map[int]bool) // true means outer
processedIndexes := make(map[int]bool) // true means outer
indexesToDelete := make(map[int]bool) // true means outer
for i := 0; i < lenAll; i++ {
if _, deleted := indexesToDelete[i]; deleted {
if _, processed := processedIndexes[i]; processed {
continue
}
iIsOuter := i < lenOuters
equalIndexes := make(map[int]bool) // true means outer
equalIndexes[i] = iIsOuter
for j := i + 1; j < lenAll; j++ {
if _, deleted := indexesToDelete[j]; deleted {
if _, processed := processedIndexes[j]; processed {
continue
}
jIsOuter := j < lenOuters
Expand All @@ -202,6 +203,11 @@ func dedupeInnersOuters(outers [][][2]float64, inners [][][2]float64) ([][][2]fl
}
equalIndexes[j] = jIsOuter
}
if len(equalIndexes) <= 1 {
continue
}
maps.Copy(processedIndexes, equalIndexes)

lenEqualOuters := countVals(equalIndexes, true)
lenEqualInners := countVals(equalIndexes, false)
difference := int(math.Abs(float64(lenEqualOuters) - float64(lenEqualInners)))
Expand All @@ -225,6 +231,10 @@ func dedupeInnersOuters(outers [][][2]float64, inners [][][2]float64) ([][][2]fl
}
}
}

if len(indexesToDelete) == 0 {
return outers, inners
}
newOuters := deleteFromSliceByIndex(outers, indexesToDelete, 0)
newInners := deleteFromSliceByIndex(inners, indexesToDelete, lenOuters)
return newOuters, newInners
Expand Down

0 comments on commit 2e31eef

Please sign in to comment.