forked from TrueCloudLab/frostfs-node
[#365] settlement/basic: Use big.Int constructor for unification
Check if `new(big.Int)` will be efficient later and replace all `big.NewInt()` in code or leave it as it is. Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
6a9a2b5d04
commit
3775d61ccb
4 changed files with 8 additions and 8 deletions
|
@ -93,7 +93,7 @@ func calculateBasicSum(size, rate uint64, ln int) *big.Int {
|
|||
|
||||
total := size * uint64(ln)
|
||||
|
||||
price := new(big.Int).SetUint64(total)
|
||||
price := big.NewInt(0).SetUint64(total)
|
||||
price.Mul(price, bigRate)
|
||||
price.Div(price, bigGB)
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ func (inc *IncomeSettlementContext) Distribute() {
|
|||
|
||||
func normalizedValue(n, total, limit *big.Int) *big.Int {
|
||||
if limit.Cmp(bigZero) == 0 {
|
||||
return new(big.Int)
|
||||
return big.NewInt(0)
|
||||
}
|
||||
|
||||
n.Mul(n, limit)
|
||||
|
|
|
@ -44,10 +44,10 @@ func TestNormalizedValues(t *testing.T) {
|
|||
}
|
||||
|
||||
func testNormalizedValues(t *testing.T, c normalizedValueCase) {
|
||||
n := new(big.Int).SetUint64(c.n)
|
||||
total := new(big.Int).SetUint64(c.total)
|
||||
limit := new(big.Int).SetUint64(c.limit)
|
||||
exp := new(big.Int).SetUint64(c.expected)
|
||||
n := big.NewInt(0).SetUint64(c.n)
|
||||
total := big.NewInt(0).SetUint64(c.total)
|
||||
limit := big.NewInt(0).SetUint64(c.limit)
|
||||
exp := big.NewInt(0).SetUint64(c.expected)
|
||||
|
||||
got := normalizedValue(n, total, limit)
|
||||
require.Zero(t, exp.Cmp(got), c.name)
|
||||
|
|
|
@ -17,12 +17,12 @@ func (t *NodeSizeTable) Put(id []byte, avg uint64) {
|
|||
}
|
||||
|
||||
func (t *NodeSizeTable) Total() *big.Int {
|
||||
return new(big.Int).SetUint64(t.total)
|
||||
return big.NewInt(0).SetUint64(t.total)
|
||||
}
|
||||
|
||||
func (t *NodeSizeTable) Iterate(f func([]byte, *big.Int)) {
|
||||
for k, v := range t.prices {
|
||||
n := new(big.Int).SetUint64(v)
|
||||
n := big.NewInt(0).SetUint64(v)
|
||||
f([]byte(k), n)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue