summaryrefslogtreecommitdiff
path: root/internal/quorum.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2023-05-20 01:35:31 +0300
committerPaul Buetow <paul@buetow.org>2023-05-20 01:35:31 +0300
commit7e33bdc70eb397882fbe989fee1fa00385335917 (patch)
treebfa10c6eb41f60fbb879950f9c6e489ee3dc6a52 /internal/quorum.go
parent62f88b8d92b3358213f9af765422f871494ed93b (diff)
can determine the winner
Diffstat (limited to 'internal/quorum.go')
-rw-r--r--internal/quorum.go9
1 files changed, 9 insertions, 0 deletions
diff --git a/internal/quorum.go b/internal/quorum.go
index 032ebc8..b506bfb 100644
--- a/internal/quorum.go
+++ b/internal/quorum.go
@@ -1,6 +1,7 @@
package internal
import (
+ "fmt"
"log"
"sort"
)
@@ -17,6 +18,14 @@ func (q quorumMap) vote(v vote) {
q[v.from] = v
}
+func (q quorumMap) winner(config config) (string, error) {
+ scores := q.score(config)
+ if len(scores) == 0 {
+ return "", fmt.Errorf("unable to find a winner, empty score list")
+ }
+ return scores[0].id, nil
+}
+
func (q quorumMap) score(config config) (scores []score) {
q.cleanExpired()
scoreMap := make(map[string]int)