-
Notifications
You must be signed in to change notification settings - Fork 669
/
unary_snowball.go
49 lines (40 loc) · 1.13 KB
/
unary_snowball.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package snowball
import (
"fmt"
)
var _ UnarySnowball = &unarySnowball{}
// unarySnowball is the implementation of a unary snowball instance
type unarySnowball struct {
// wrap the unary snowflake logic
unarySnowflake
// numSuccessfulPolls tracks the total number of successful network polls
numSuccessfulPolls int
}
func (sb *unarySnowball) RecordSuccessfulPoll() {
sb.numSuccessfulPolls++
sb.unarySnowflake.RecordSuccessfulPoll()
}
func (sb *unarySnowball) Extend(beta int, choice int) BinarySnowball {
bs := &binarySnowball{
binarySnowflake: binarySnowflake{
binarySlush: binarySlush{preference: choice},
confidence: sb.confidence,
beta: beta,
finalized: sb.Finalized(),
},
preference: choice,
}
bs.numSuccessfulPolls[choice] = sb.numSuccessfulPolls
return bs
}
func (sb *unarySnowball) Clone() UnarySnowball {
newSnowball := *sb
return &newSnowball
}
func (sb *unarySnowball) String() string {
return fmt.Sprintf("SB(NumSuccessfulPolls = %d, %s)",
sb.numSuccessfulPolls,
&sb.unarySnowflake)
}