diff options
| author | Paul Buetow <paul@buetow.org> | 2023-05-20 00:37:27 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2023-05-20 00:37:27 +0300 |
| commit | 5b62dff074a0ef52c9ba1bb87ced6947d9bf6782 (patch) | |
| tree | ad78cf72f2b2b2b3c6347ba7be4473cf91e059ad /internal/quorum.go | |
| parent | 22c04663bf832506b14fa1d2ab5a88d519bbd659 (diff) | |
can test clean expiry
Diffstat (limited to 'internal/quorum.go')
| -rw-r--r-- | internal/quorum.go | 39 |
1 files changed, 31 insertions, 8 deletions
diff --git a/internal/quorum.go b/internal/quorum.go index 1c8e451..964d465 100644 --- a/internal/quorum.go +++ b/internal/quorum.go @@ -2,6 +2,7 @@ package internal import ( "log" + "sort" ) type quorumMap map[string]vote @@ -17,15 +18,37 @@ func (q quorumMap) vote(v vote) { } func (q quorumMap) score() (scores []score) { - /* - scoreMap := make(map[string]int) - var expired []string + q.cleanExpired() + scoreMap := make(map[string]int) - for from, vote := range q { - - for _, id := range vote.ids { - } + for _, vote := range q { + for _, id := range vote.ids { + score, _ := scoreMap[id] + scoreMap[id] = score + 1 } - */ + } + + for id, score_ := range scoreMap { + scores = append(scores, score{id, score_}) + } + + sort.Slice(scores, func(i, j int) bool { + return scores[i].score < scores[j].score + }) + return } + +func (q quorumMap) cleanExpired() { + var expired []string + + for from, vote := range q { + if vote.expired() { + expired = append(expired, from) + } + } + + for _, e := range expired { + delete(q, e) + } +} |
