Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
DisSys Inc.
bsc-shamir
Commits
2384e917
Commit
2384e917
authored
Jun 04, 2020
by
Mikkel Wienberg Madsen
👀
Browse files
Cheesy
parent
38179269
Pipeline
#21909
passed with stages
in 2 minutes and 30 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
election/agreement.go
View file @
2384e917
...
...
@@ -80,18 +80,20 @@ func MaxSubset(t int, superset []BallotList) map[string]bool {
combis
:=
combin
.
Combinations
(
n
,
t
)
log
.
Printf
(
"N: %d, combis: %d
\n
"
,
n
,
len
(
combis
))
subsets
:=
make
([]
map
[
string
]
bool
,
len
(
combis
),
n
)
max
:=
0
best
:=
len
(
Union
(
superset
))
for
i
,
ls
:=
range
combis
{
sets
:=
make
([]
BallotList
,
0
,
len
(
ls
))
for
_
,
i
:=
range
ls
{
sets
=
append
(
sets
,
superset
[
i
])
}
subsets
[
i
]
=
Intersection
(
sets
)
}
max
:=
0
for
i
:=
0
;
i
<
len
(
subsets
);
i
++
{
if
len
(
subsets
[
i
])
>
max
{
max
=
i
}
if
len
(
subsets
[
i
])
==
best
{
break
}
}
return
subsets
[
max
]
}
...
...
@@ -112,3 +114,13 @@ func Intersection(superset []BallotList) map[string]bool {
}
return
set
}
func
Union
(
superset
[]
BallotList
)
map
[
string
]
bool
{
union
:=
make
(
map
[
string
]
bool
)
for
_
,
set
:=
range
superset
{
for
hash
:=
range
set
{
union
[
hash
]
=
true
}
}
return
union
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment