Documentation
¶
Overview ¶
Package rollup is the holder for package bom. It turns a named bill of materials into the call the machine is, and its loop is the trampoline that evaluates the call until it returns. The walk, the stack and the numbers are the machine's; nothing here recurses.
Example ¶
A bicycle: the frame and seat are bought in, each wheel is built from a rim, a tyre, 32 spokes and a hub, and each hub holds two bearings. Values are in cents, and an assembly's value is the labour to put it together.
package main
import (
"fmt"
"code.eitanity.com/merilo/examples/bom/rollup"
)
func main() {
const (
bicycle = iota
frame
seat
wheel
rim
tyre
spoke
hub
bearing
)
bill := rollup.Bill{Top: bicycle, Parts: []rollup.Part{
bicycle: {Name: "bicycle", Value: 4000, Lines: []rollup.Line{{Part: frame, Quantity: 1}, {Part: seat, Quantity: 1}, {Part: wheel, Quantity: 2}}},
frame: {Name: "frame", Value: 12000},
seat: {Name: "seat", Value: 2500},
wheel: {Name: "wheel", Value: 1500, Lines: []rollup.Line{{Part: rim, Quantity: 1}, {Part: tyre, Quantity: 1}, {Part: spoke, Quantity: 32}, {Part: hub, Quantity: 1}}},
rim: {Name: "rim", Value: 3000},
tyre: {Name: "tyre", Value: 1800},
spoke: {Name: "spoke", Value: 40},
hub: {Name: "hub", Value: 600, Lines: []rollup.Line{{Part: bearing, Quantity: 2}}},
bearing: {Name: "bearing", Value: 350},
}}
r, err := rollup.Run(bill, 1000)
if err != nil {
fmt.Println(err)
return
}
for i, p := range bill.Parts {
fmt.Printf("%-8s need %3v subtotal %6v\n", p.Name, r.Need[i], r.Subtotal[i])
}
fmt.Println("total", r.Total)
}
Output: bicycle need 1 subtotal 36260 frame need 1 subtotal 12000 seat need 1 subtotal 2500 wheel need 2 subtotal 8880 rim need 2 subtotal 3000 tyre need 2 subtotal 1800 spoke need 64 subtotal 40 hub need 2 subtotal 1300 bearing need 4 subtotal 350 total 36260
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Line ¶
type Line struct {
Part int // the part, an index into Bill.Parts
Quantity int64 // how many, at least one
}
Line is a quantity of one part in another.
type Part ¶
Part is a part or an assembly. Its value is its own cost, such as the labour to assemble it, in the smallest unit of currency.
type Result ¶
type Result struct {
// Subtotal is, for each part, the cost of one: its value plus each
// line's quantity times that part's subtotal. It is zero for a part
// the system does not use.
Subtotal []int64
// Need is, for each part, how many one system takes in all: the
// quantities multiplied down every path to it and summed. The system
// itself needs one.
Need []int64
// Total is the cost of one system, its subtotal.
Total int64
}
Result is a finished rollup.
type Walker ¶
type Walker struct {
// contains filtered or unexported fields
}
Walker is one rollup in progress: the call, the bill's size and its top part.