ballholders

package
v0.0.0-...-b152c66 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 5, 2013 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

things that hold balls

For example, the clock's ball queue is a queue. The clock's time rails are Rails, and both are BallHolders.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BallHolder

type BallHolder struct {
	// contains filtered or unexported fields
}

A BallHolder is a thing that holds Balls

func NewBallHolder

func NewBallHolder(capacity uint8, nBalls uint8) BallHolder

Create a new BallHolder

func (BallHolder) IsFull

func (bh BallHolder) IsFull() bool

type Queue

type Queue struct {
	BallHolder
	// contains filtered or unexported fields
}

The clock's queue

Queue uses a ring buffer to store the balls; instead of the balls moving within the Queue, the ring buffer is updated to point to the appropriate ball.

Because balls are only ever appended, nBalls is used to determine which of the balls are valid, and the rest of the queue is considered empty.

func NewQueue

func NewQueue(capacity uint8) Queue

Create a new, full, BallHolder

func (*Queue) DoCycleCheck

func (q *Queue) DoCycleCheck() bool

Return true if the balls are in their original position in the queue

func (*Queue) GetTestRepr

func (q *Queue) GetTestRepr() []int

Return a representation of the queue for testing

-1 means empty

func (*Queue) Pop

func (q *Queue) Pop() ball.Ball

Get a ball from the beginning of the queue

func (*Queue) Push

func (q *Queue) Push(balls []ball.Ball)

Put an array of balls back to the end of the queue

type Rail

type Rail struct {
	BallHolder
	Balls []ball.Ball
}

The clock's time rails

A Rail holds Balls, but can spill them (down to another ball holder)

Rail uses an array to store the balls.

Unlike a Queue, balls are never "popped" one at a time; instead, when the rail is full, all balls are spilled in reverse order.

Because balls are only ever appended, nBalls is used to determine where to put the balls in the array, and to determine which of the balls are valid, while the rest of the array is considered empty.

func NewRail

func NewRail(capacity uint8) Rail

Create a new, empty, Rail

func (*Rail) GetTestRepr

func (r *Rail) GetTestRepr() []int

Return a representation of the rail for testing

-1 means empty

func (*Rail) Push

func (r *Rail) Push(b ball.Ball) []ball.Ball

Add a ball to the rail. If the rail is full, it will spill. A slice of spilled balls is returned.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL