/*
* Just some simple things in a package.
*/
package simple
import "strconv"
// This is essentially private, because it starts with a lower-case letter.
var value int
// This is visible.
var Label string = "Simple"
// This is public, too. But not its contents, since they're all lc.
type Collection struct {
left int
right int
}
// Here are some public methods.
func (c *Collection) Init(l int, r int) {
c.left = l
c.right = r
}
func (c *Collection) Swap() {
c.left, c.right = c.right, c.left
}
func (c *Collection) Move(m int) {
c.left, c.right = c.left + m, c.right - m
}
// Here's some private functions
func (c *Collection) max() int {
if c.right > c.left {
return c.right
} else {
return c.left
}
}
func (c *Collection) min() int {
if c.right < c.left {
return c.right
} else {
return c.left
}
}
// A public one that uses the private ones.
func (c *Collection) Sort() {
c.left, c.right = c.min(), c.max()
}
// Get the information
func (c *Collection) Report() string {
return Label + " " + strconv.Itoa(c.left) + " " + strconv.Itoa(c.right)
}
// There's no rule against public top-level fuctions
func Version() string {
return "Simple 1.143"
}