Skip to content

Commit

Permalink
New Compute function optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
janos committed Jan 23, 2023
1 parent 00daf99 commit f1d00b9
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions schulze.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,20 +195,23 @@ func calculatePairwiseStrengths[C comparable](choices []C, preferences []int) []
for i := uintptr(0); i < choicesCount; i++ {
for j := uintptr(0); j < choicesCount; j++ {
// removed unnecessary check for optimization: if i == j { continue }
ji := j*choicesCount + i
jip := *(*int)(unsafe.Add(strengthsPtr, ji*intSize))
for k := uintptr(0); k < choicesCount; k++ {
// removed unnecessary check for optimization: if i == k || j == k { continue }
jk := j*choicesCount + k
ji := j*choicesCount + i
ik := i*choicesCount + k
jkp := (*int)(unsafe.Add(strengthsPtr, jk*intSize))
m := max(
*jkp,
min(
*(*int)(unsafe.Add(strengthsPtr, ji*intSize)),
jip,
*(*int)(unsafe.Add(strengthsPtr, ik*intSize)),
),
)
*(jkp) = m
if *jkp != m {
*jkp = m
}
}
}
}
Expand Down

0 comments on commit f1d00b9

Please sign in to comment.