Documentation ¶
Index ¶
- Constants
- Variables
- type Amount
- type ExpendCombine
- type ExpendGenericOrder
- type ExpendStatistical
- type ExpendStrategy
- type Nominal
- type NominalGroup
- func (ng *NominalGroup) Add(n Nominal, count uint) error
- func (ng *NominalGroup) AddFrom(source *NominalGroup)
- func (ng *NominalGroup) Clear()
- func (ng *NominalGroup) Copy() *NominalGroup
- func (ng *NominalGroup) Diff(other *NominalGroup) Amount
- func (ng *NominalGroup) Get(n Nominal) (uint, error)
- func (ng *NominalGroup) Iter(f func(nominal Nominal, count uint) error) error
- func (ng *NominalGroup) MustAdd(n Nominal, count uint)
- func (ng *NominalGroup) SetValid(valid []Nominal)
- func (ng *NominalGroup) String() string
- func (ng *NominalGroup) Sub(other *NominalGroup)
- func (ng *NominalGroup) ToMapUint32(m map[uint32]uint32)
- func (ng *NominalGroup) Total() Amount
- func (ng *NominalGroup) Withdraw(to *NominalGroup, a Amount, strategy ExpendStrategy) error
Constants ¶
View Source
const MaxAmount = Amount(math.MaxUint32)
Variables ¶
View Source
var ( ErrNominalInvalid = errors.New("Nominal is not valid for this group") ErrNominalCount = errors.New("Not enough nominals for this amount") )
Functions ¶
This section is empty.
Types ¶
type Amount ¶
type Amount uint32
Amount is integer counting lowest currency unit, e.g. $1.20 = 120
func (Amount) AddPersent ¶ added in v0.220223.0
func (Amount) Format100I ¶
type ExpendCombine ¶
type ExpendCombine struct { S1 ExpendStrategy S2 ExpendStrategy Ratio float32 // contains filtered or unexported fields }
func (*ExpendCombine) ExpendOne ¶
func (ec *ExpendCombine) ExpendOne(from *NominalGroup, max Amount) (Nominal, error)
func (*ExpendCombine) Reset ¶
func (ec *ExpendCombine) Reset(from *NominalGroup)
func (*ExpendCombine) Validate ¶
func (ec *ExpendCombine) Validate() bool
type ExpendGenericOrder ¶
type ExpendGenericOrder struct { SortElemFunc ngOrderSortElemFunc // contains filtered or unexported fields }
func (*ExpendGenericOrder) ExpendOne ¶
func (ego *ExpendGenericOrder) ExpendOne(from *NominalGroup, max Amount) (Nominal, error)
func (*ExpendGenericOrder) Reset ¶
func (ego *ExpendGenericOrder) Reset(from *NominalGroup)
func (*ExpendGenericOrder) Validate ¶
func (ego *ExpendGenericOrder) Validate() bool
type ExpendStatistical ¶
type ExpendStatistical struct { Stat *NominalGroup // contains filtered or unexported fields }
func (*ExpendStatistical) ExpendOne ¶
func (es *ExpendStatistical) ExpendOne(from *NominalGroup, max Amount) (Nominal, error)
func (*ExpendStatistical) Reset ¶
func (es *ExpendStatistical) Reset(from *NominalGroup)
func (*ExpendStatistical) Validate ¶
func (es *ExpendStatistical) Validate() bool
type ExpendStrategy ¶
type ExpendStrategy interface { Reset(from *NominalGroup) ExpendOne(from *NominalGroup, max Amount) (Nominal, error) Validate() bool }
NominalGroup.Withdraw = strategy.Reset + loop strategy.ExpendOne
func NewExpendLeastCount ¶
func NewExpendLeastCount() ExpendStrategy
func NewExpendMostAvailable ¶
func NewExpendMostAvailable() ExpendStrategy
type NominalGroup ¶
type NominalGroup struct {
// contains filtered or unexported fields
}
NominalGroup operates money comprised of multiple nominals, like coins or bills. coin1 : 3 coin5 : 1 coin10: 4 total : 48
func (*NominalGroup) AddFrom ¶
func (ng *NominalGroup) AddFrom(source *NominalGroup)
func (*NominalGroup) Clear ¶
func (ng *NominalGroup) Clear()
func (*NominalGroup) Copy ¶
func (ng *NominalGroup) Copy() *NominalGroup
func (*NominalGroup) Diff ¶
func (ng *NominalGroup) Diff(other *NominalGroup) Amount
func (*NominalGroup) Iter ¶
func (ng *NominalGroup) Iter(f func(nominal Nominal, count uint) error) error
func (*NominalGroup) MustAdd ¶
func (ng *NominalGroup) MustAdd(n Nominal, count uint)
MustAdd just adds count ignoring valid nominals.
func (*NominalGroup) SetValid ¶
func (ng *NominalGroup) SetValid(valid []Nominal)
func (*NominalGroup) String ¶
func (ng *NominalGroup) String() string
func (*NominalGroup) Sub ¶
func (ng *NominalGroup) Sub(other *NominalGroup)
func (*NominalGroup) ToMapUint32 ¶
func (ng *NominalGroup) ToMapUint32(m map[uint32]uint32)
func (*NominalGroup) Total ¶
func (ng *NominalGroup) Total() Amount
func (*NominalGroup) Withdraw ¶
func (ng *NominalGroup) Withdraw(to *NominalGroup, a Amount, strategy ExpendStrategy) error
Click to show internal directories.
Click to hide internal directories.