Skip to content
Snippets Groups Projects
Commit 861783f5 authored by Luca Moser's avatar Luca Moser
Browse files

renames rng for opinion giver

parent f76a391b
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment