refactor: replace min/max helpers with built-in min/max
We can use the built-in `min` and `max` functions since Go 1.21. Reference: https://go.dev/ref/spec#Min_and_max Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
This commit is contained in:
7 files changed
+6
-116
No files matched your search
@@ -85,9 +85,7 @@ func NewSimpleGraph(g ChannelGraph) (*SimpleGraph, error) {
|
|||||||
func maxVal(mapping map[int]uint32) uint32 {
|
func maxVal(mapping map[int]uint32) uint32 {
|
||||||
maxValue := uint32(0)
|
maxValue := uint32(0)
|
||||||
for _, value := range mapping {
|
for _, value := range mapping {
|
||||||
if maxValue < value {
|
maxValue = max(maxValue, value)
|
||||||
maxValue = value
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return maxValue
|
return maxValue
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,26 +0,0 @@
|
|||||||
package lntypes
|
|
||||||
|
|
||||||
import "golang.org/x/exp/constraints"
|
|
||||||
|
|
||||||
// Number defines a type constraint for numbers.
|
|
||||||
type Number interface {
|
|
||||||
constraints.Integer | constraints.Float
|
|
||||||
}
|
|
||||||
|
|
||||||
// Max returns the greater of the two inputs.
|
|
||||||
func Max[N Number](op1 N, op2 N) N {
|
|
||||||
if op1 > op2 {
|
|
||||||
return op1
|
|
||||||
}
|
|
||||||
|
|
||||||
return op2
|
|
||||||
}
|
|
||||||
|
|
||||||
// Min returns the lesser of the two inputs.
|
|
||||||
func Min[N Number](op1 N, op2 N) N {
|
|
||||||
if op1 < op2 {
|
|
||||||
return op1
|
|
||||||
}
|
|
||||||
|
|
||||||
return op2
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
package lntypes
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
)
|
|
||||||
|
|
||||||
// TestMin tests getting correct minimal numbers.
|
|
||||||
func TestMin(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
require.Equal(t, 1, Min(1, 1))
|
|
||||||
require.Equal(t, 1, Min(1, 2))
|
|
||||||
require.Equal(t, 1.5, Min(1.5, 2.5))
|
|
||||||
}
|
|
||||||
|
|
||||||
// TestMax tests getting correct maximal numbers.
|
|
||||||
func TestMax(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
require.Equal(t, 1, Max(1, 1))
|
|
||||||
require.Equal(t, 2, Max(1, 2))
|
|
||||||
require.Equal(t, 2.5, Max(1.5, 2.5))
|
|
||||||
}
|
|
||||||
@@ -6,7 +6,6 @@ import (
|
|||||||
"github.com/btcsuite/btcd/btcutil"
|
"github.com/btcsuite/btcd/btcutil"
|
||||||
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
||||||
"github.com/lightningnetwork/lnd/graph/db/models"
|
"github.com/lightningnetwork/lnd/graph/db/models"
|
||||||
"github.com/lightningnetwork/lnd/lntypes"
|
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
"github.com/lightningnetwork/lnd/routing/route"
|
"github.com/lightningnetwork/lnd/routing/route"
|
||||||
)
|
)
|
||||||
@@ -379,13 +378,11 @@ func (u *edgeUnifier) getEdgeNetwork(netAmtReceived lnwire.MilliSatoshi,
|
|||||||
|
|
||||||
capMsat = edge.policy.MaxHTLC
|
capMsat = edge.policy.MaxHTLC
|
||||||
}
|
}
|
||||||
maxCapMsat = lntypes.Max(capMsat, maxCapMsat)
|
maxCapMsat = max(capMsat, maxCapMsat)
|
||||||
|
|
||||||
// Track the maximum time lock of all channels that are
|
// Track the maximum time lock of all channels that are
|
||||||
// candidate for non-strict forwarding at the routing node.
|
// candidate for non-strict forwarding at the routing node.
|
||||||
maxTimelock = lntypes.Max(
|
maxTimelock = max(maxTimelock, edge.policy.TimeLockDelta)
|
||||||
maxTimelock, edge.policy.TimeLockDelta,
|
|
||||||
)
|
|
||||||
|
|
||||||
outboundFee := int64(edge.policy.ComputeFee(amt))
|
outboundFee := int64(edge.policy.ComputeFee(amt))
|
||||||
fee := outboundFee + inboundFee
|
fee := outboundFee + inboundFee
|
||||||
@@ -440,10 +437,10 @@ func (u *edgeUnifier) getEdgeNetwork(netAmtReceived lnwire.MilliSatoshi,
|
|||||||
|
|
||||||
// minAmt returns the minimum amount that can be forwarded on this connection.
|
// minAmt returns the minimum amount that can be forwarded on this connection.
|
||||||
func (u *edgeUnifier) minAmt() lnwire.MilliSatoshi {
|
func (u *edgeUnifier) minAmt() lnwire.MilliSatoshi {
|
||||||
min := lnwire.MaxMilliSatoshi
|
minAmount := lnwire.MaxMilliSatoshi
|
||||||
for _, edge := range u.edges {
|
for _, edge := range u.edges {
|
||||||
min = lntypes.Min(min, edge.policy.MinHTLC)
|
minAmount = min(minAmount, edge.policy.MinHTLC)
|
||||||
}
|
}
|
||||||
|
|
||||||
return min
|
return minAmount
|
||||||
}
|
}
|
||||||
@@ -74,24 +74,6 @@ func (a *RangeIndex) addRange(start, end uint64) error {
|
|||||||
"than end height %d", start, end)
|
"than end height %d", start, end)
|
||||||
}
|
}
|
||||||
|
|
||||||
// min is a helper closure that will return the minimum of two uint64s.
|
|
||||||
min := func(a, b uint64) uint64 {
|
|
||||||
if a < b {
|
|
||||||
return a
|
|
||||||
}
|
|
||||||
|
|
||||||
return b
|
|
||||||
}
|
|
||||||
|
|
||||||
// max is a helper closure that will return the maximum of two uint64s.
|
|
||||||
max := func(a, b uint64) uint64 {
|
|
||||||
if a > b {
|
|
||||||
return a
|
|
||||||
}
|
|
||||||
|
|
||||||
return b
|
|
||||||
}
|
|
||||||
|
|
||||||
// Collect the ranges that fall before and after the new range along
|
// Collect the ranges that fall before and after the new range along
|
||||||
// with the start and end values of the new range.
|
// with the start and end values of the new range.
|
||||||
var before, after []rangeItem
|
var before, after []rangeItem
|
||||||
|
|||||||
@@ -74,24 +74,6 @@ func (a *RangeIndex) addRange(start, end uint64) error {
|
|||||||
"than end height %d", start, end)
|
"than end height %d", start, end)
|
||||||
}
|
}
|
||||||
|
|
||||||
// min is a helper closure that will return the minimum of two uint64s.
|
|
||||||
min := func(a, b uint64) uint64 {
|
|
||||||
if a < b {
|
|
||||||
return a
|
|
||||||
}
|
|
||||||
|
|
||||||
return b
|
|
||||||
}
|
|
||||||
|
|
||||||
// max is a helper closure that will return the maximum of two uint64s.
|
|
||||||
max := func(a, b uint64) uint64 {
|
|
||||||
if a > b {
|
|
||||||
return a
|
|
||||||
}
|
|
||||||
|
|
||||||
return b
|
|
||||||
}
|
|
||||||
|
|
||||||
// Collect the ranges that fall before and after the new range along
|
// Collect the ranges that fall before and after the new range along
|
||||||
// with the start and end values of the new range.
|
// with the start and end values of the new range.
|
||||||
var before, after []rangeItem
|
var before, after []rangeItem
|
||||||
|
|||||||
@@ -74,24 +74,6 @@ func (a *RangeIndex) addRange(start, end uint64) error {
|
|||||||
"than end height %d", start, end)
|
"than end height %d", start, end)
|
||||||
}
|
}
|
||||||
|
|
||||||
// min is a helper closure that will return the minimum of two uint64s.
|
|
||||||
min := func(a, b uint64) uint64 {
|
|
||||||
if a < b {
|
|
||||||
return a
|
|
||||||
}
|
|
||||||
|
|
||||||
return b
|
|
||||||
}
|
|
||||||
|
|
||||||
// max is a helper closure that will return the maximum of two uint64s.
|
|
||||||
max := func(a, b uint64) uint64 {
|
|
||||||
if a > b {
|
|
||||||
return a
|
|
||||||
}
|
|
||||||
|
|
||||||
return b
|
|
||||||
}
|
|
||||||
|
|
||||||
// Collect the ranges that fall before and after the new range along
|
// Collect the ranges that fall before and after the new range along
|
||||||
// with the start and end values of the new range.
|
// with the start and end values of the new range.
|
||||||
var before, after []rangeItem
|
var before, after []rangeItem
|
||||||
|
|||||||
Reference in new issue
Block a user