فهرست منبع

fix golint issues in core/mathx (#498)

Kevin Wan 4 سال پیش
والد
کامیت
8872d7cbd3
4فایلهای تغییر یافته به همراه10 افزوده شده و 0 حذف شده
  1. 1 0
      core/mathx/entropy.go
  2. 2 0
      core/mathx/int.go
  3. 3 0
      core/mathx/proba.go
  4. 4 0
      core/mathx/unstable.go

+ 1 - 0
core/mathx/entropy.go

@@ -4,6 +4,7 @@ import "math"
 
 const epsilon = 1e-6
 
+// CalcEntropy calculates the entropy of m.
 func CalcEntropy(m map[interface{}]int) float64 {
 	if len(m) == 0 || len(m) == 1 {
 		return 1

+ 2 - 0
core/mathx/int.go

@@ -1,5 +1,6 @@
 package mathx
 
+// MaxInt returns the larger one of a and b.
 func MaxInt(a, b int) int {
 	if a > b {
 		return a
@@ -8,6 +9,7 @@ func MaxInt(a, b int) int {
 	return b
 }
 
+// MinInt returns the smaller one of a and b.
 func MinInt(a, b int) int {
 	if a < b {
 		return a

+ 3 - 0
core/mathx/proba.go

@@ -6,18 +6,21 @@ import (
 	"time"
 )
 
+// A Proba is used to test if true on given probability.
 type Proba struct {
 	// rand.New(...) returns a non thread safe object
 	r    *rand.Rand
 	lock sync.Mutex
 }
 
+// NewProba returns a Proba.
 func NewProba() *Proba {
 	return &Proba{
 		r: rand.New(rand.NewSource(time.Now().UnixNano())),
 	}
 }
 
+// TrueOnProba checks if true on given probability.
 func (p *Proba) TrueOnProba(proba float64) (truth bool) {
 	p.lock.Lock()
 	truth = p.r.Float64() < proba

+ 4 - 0
core/mathx/unstable.go

@@ -6,12 +6,14 @@ import (
 	"time"
 )
 
+// A Unstable is used to generate random value around the mean value base on given deviation.
 type Unstable struct {
 	deviation float64
 	r         *rand.Rand
 	lock      *sync.Mutex
 }
 
+// NewUnstable returns a Unstable.
 func NewUnstable(deviation float64) Unstable {
 	if deviation < 0 {
 		deviation = 0
@@ -26,6 +28,7 @@ func NewUnstable(deviation float64) Unstable {
 	}
 }
 
+// AroundDuration returns a random duration with given base and deviation.
 func (u Unstable) AroundDuration(base time.Duration) time.Duration {
 	u.lock.Lock()
 	val := time.Duration((1 + u.deviation - 2*u.deviation*u.r.Float64()) * float64(base))
@@ -33,6 +36,7 @@ func (u Unstable) AroundDuration(base time.Duration) time.Duration {
 	return val
 }
 
+// AroundInt returns a randome int64 with given base and deviation.
 func (u Unstable) AroundInt(base int64) int64 {
 	u.lock.Lock()
 	val := int64((1 + u.deviation - 2*u.deviation*u.r.Float64()) * float64(base))