Commit 38179269 authored by Mikkel Wienberg Madsen's avatar Mikkel Wienberg Madsen 👀
Browse files

Optimize intersection

parent 884ce98a
Pipeline #21908 passed with stages
in 2 minutes and 24 seconds
......@@ -75,15 +75,15 @@ func (a *Agreement) TallyList() ([]uuid.UUID, error) {
return list, nil
}
func MaxSubset(t int, ballotLists []BallotList) map[string]bool {
n := len(ballotLists)
func MaxSubset(t int, superset []BallotList) map[string]bool {
n := len(superset)
combis := combin.Combinations(n, t)
log.Printf("N: %d, combis: %d\n", n, len(combis))
subsets := make([]map[string]bool, len(combis), n)
for i, ls := range combis {
sets := make([]BallotList, 0, len(ls))
for _, i := range ls {
sets = append(sets, ballotLists[i])
sets = append(sets, superset[i])
}
subsets[i] = Intersection(sets)
}
......@@ -97,15 +97,16 @@ func MaxSubset(t int, ballotLists []BallotList) map[string]bool {
}
func Intersection(superset []BallotList) map[string]bool {
section := make(map[string]int, len(superset[0]))
for _, set := range superset {
for hash := range set {
section[hash]++
}
}
set := make(map[string]bool)
for hash, num := range section {
if num >= len(superset) {
for hash := range superset[0] {
good := true
for _, set := range superset {
if _, ok := set[hash]; !ok {
good = false
break
}
}
if good {
set[hash] = true
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment