From 861783f53270ce438a4713e9abb16a8fbbefe7dd Mon Sep 17 00:00:00 2001 From: Luca Moser <moser.luca@gmail.com> Date: Wed, 15 Apr 2020 10:38:09 +0200 Subject: [PATCH] renames rng for opinion giver --- packages/vote/fpc/fpc.go | 9 +++++---- packages/vote/fpc/vote_context.go | 7 ++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/vote/fpc/fpc.go b/packages/vote/fpc/fpc.go index 47ae4a2e..79787d17 100644 --- a/packages/vote/fpc/fpc.go +++ b/packages/vote/fpc/fpc.go @@ -23,7 +23,7 @@ func New(opinionGiverFunc vote.OpinionGiverFunc, paras ...*Parameters) *FPC { f := &FPC{ opinionGiverFunc: opinionGiverFunc, paras: DefaultParameters(), - rng: rand.New(rand.NewSource(time.Now().UnixNano())), + opinionGiverRng: rand.New(rand.NewSource(time.Now().UnixNano())), ctxs: make(map[string]*VoteContext), queue: list.New(), queueSet: make(map[string]struct{}), @@ -54,9 +54,10 @@ type FPC struct { ctxsMu sync.RWMutex // parameters to use within FPC. paras *Parameters - // indicates whether the last round was performed successfully + // indicates whether the last round was performed successfully. lastRoundCompletedSuccessfully bool - rng *rand.Rand + // used to randomly select opinion givers. + opinionGiverRng *rand.Rand } func (f *FPC) Vote(id string, initOpn vote.Opinion) error { @@ -188,7 +189,7 @@ func (f *FPC) queryOpinions() error { // select random subset to query (the same opinion giver can occur multiple times) opinionGiversToQuery := make([]vote.OpinionGiver, f.paras.QuerySampleSize) for i := 0; i < f.paras.QuerySampleSize; i++ { - opinionGiversToQuery[i] = opinionGivers[f.rng.Intn(len(opinionGivers))] + opinionGiversToQuery[i] = opinionGivers[f.opinionGiverRng.Intn(len(opinionGivers))] } // votes per id diff --git a/packages/vote/fpc/vote_context.go b/packages/vote/fpc/vote_context.go index 862dc769..fb4ae5e8 100644 --- a/packages/vote/fpc/vote_context.go +++ b/packages/vote/fpc/vote_context.go @@ -22,11 +22,12 @@ type VoteContext struct { Opinions []vote.Opinion } -// adds the given opinion to this vote context +// AddOpinion adds the given opinion to this vote context. func (vc *VoteContext) AddOpinion(opn vote.Opinion) { vc.Opinions = append(vc.Opinions, opn) } +// LastOpinion returns the last formed opinion. func (vc *VoteContext) LastOpinion() vote.Opinion { return vc.Opinions[len(vc.Opinions)-1] } @@ -52,12 +53,12 @@ func (vc *VoteContext) IsFinalized(coolingOffPeriod int, finalizationThreshold i return true } -// tells whether the vote context is new. +// IsNew tells whether the vote context is new. func (vc *VoteContext) IsNew() bool { return vc.Liked == likedInit } -// tells whether the vote context just had its first round. +// HadFirstRound tells whether the vote context just had its first round. func (vc *VoteContext) HadFirstRound() bool { return vc.Rounds == 1 } -- GitLab