diff --git a/packages/vote/fpc/fpc.go b/packages/vote/fpc/fpc.go index 47ae4a2e75e7da59b22996d18422da40b8e9ea43..79787d17ad9bb0b8f15cae918dd1823206f6c7a5 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 862dc769369ca862acb78e948177d646766804a6..fb4ae5e841cd3bc8b378de791fd0de7d0ff24d01 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 }