|
|
@ -10,15 +10,13 @@ type additive struct {
|
|
|
|
total int
|
|
|
|
total int
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (*additive) MergeIdentity() *additive {
|
|
|
|
|
|
|
|
return new(additive)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (a *additive) Merge(b *additive) error {
|
|
|
|
func (a *additive) Merge(b *additive) error {
|
|
|
|
a.total += b.total
|
|
|
|
a.total += b.total
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (*additive) MergeIdentity() *additive { return new(additive) }
|
|
|
|
|
|
|
|
|
|
|
|
func add(n int) *additive {
|
|
|
|
func add(n int) *additive {
|
|
|
|
return &additive{total: n}
|
|
|
|
return &additive{total: n}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -27,9 +25,7 @@ type multiplicative struct {
|
|
|
|
scale int
|
|
|
|
scale int
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (m *multiplicative) MergeIdentity() *multiplicative {
|
|
|
|
func (*multiplicative) MergeIdentity() *multiplicative { return &multiplicative{scale: 1} }
|
|
|
|
return &multiplicative{scale: 1}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (m *multiplicative) Merge(v *multiplicative) error {
|
|
|
|
func (m *multiplicative) Merge(v *multiplicative) error {
|
|
|
|
m.scale *= v.scale
|
|
|
|
m.scale *= v.scale
|
|
|
@ -46,14 +42,14 @@ type exclusive struct {
|
|
|
|
stock int
|
|
|
|
stock int
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (*exclusive) MergeIdentity() *exclusive { return new(exclusive) }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (e *exclusive) Merge(source *exclusive) error {
|
|
|
|
func (e *exclusive) Merge(source *exclusive) error {
|
|
|
|
e.stock += source.stock
|
|
|
|
e.stock += source.stock
|
|
|
|
source.stock = 0
|
|
|
|
source.stock = 0
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (*exclusive) MergeIdentity() *exclusive { return new(exclusive) }
|
|
|
|
|
|
|
|
|
|
|
|
func ex(n int) *exclusive {
|
|
|
|
func ex(n int) *exclusive {
|
|
|
|
return &exclusive{stock: n}
|
|
|
|
return &exclusive{stock: n}
|
|
|
|
}
|
|
|
|
}
|
|
|
|