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
38179269
Commit
38179269
authored
Jun 04, 2020
by
Mikkel Wienberg Madsen
👀
Browse files
Optimize intersection
parent
884ce98a
Pipeline
#21908
passed with stages
in 2 minutes and 24 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
election/agreement.go
View file @
38179269
...
...
@@ -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
}
}
...
...
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