algs4

package module
v0.0.0-...-00bd036 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2014 License: MIT Imports: 16 Imported by: 0

README

Go libraries for Algorithms, 4th Edition

These are incomplete ports of the Java code included with Algorithms, 4th Edition. I doubt I'll ever complete them. APIs are close-ish, but Go is different than Java, so whatebbs. YMMV.

And now, an ASCII T-Rex* excited about ALGORITHM:


    8""""8 8     8""""8 8"""88 8"""8  8 ""8"" 8   8 8""8""8 8  8  8
    8    8 8     8    " 8    8 8   8  8   8   8   8 8  8  8 88 88 88
    8eeee8 8e    8e     8    8 8eee8e 8e  8e  8eee8 8e 8  8 88 88 88
    88   8 88    88  ee 8    8 88   8 88  88  88  8 88 8  8 88 88 88
    88   8 88    88   8 8    8 88   8 88  88  88  8 88 8  8
    88   8 88eee 88eee8 8eeee8 88   8 88  88  88  8 88 8  8 88 88 88



                 .-=-==--==--.
           ..-=="  ,'o`)      `.
         ,'         `"'         \
        :  (                     `.__...._
        |                  )    /         `-=-.
        :       ,vv.-._   /    /               `---==-._
         \/\/\/VV ^ d88`;'    /                         `.
             ``  ^/d88P!'    /             ,              `._
                ^/    !'   ,.      ,      /                  "-,,__,,--'""""-.
               ^/    !'  ,'  \ . .(      (         _           )  ) ) ) ))_,-.\
              ^(__ ,!',"'   ;:+.:%:a.     \:.. . ,'          )  )  ) ) ,"'    '
              ',,,'','     /o:::":%:%a.    \:.:.:         .    )  ) _,'
               """'       ;':::'' `+%%%a._  \%:%|         ;.). _,-""
                      ,-='_.-'      ``:%::)  )%:|        /:._,"
                     (/(/"           ," ,'_,'%%%:       (_,'
                                    (  (//(`.___;        \
                                     \     \    `         `
                                      `.    `.   `.        :
                                        \. . .\    : . . . :
                                         \. . .:    `.. . .:
                                          `..:.:\     \:...\
                                           ;:.:.;      ::...:
                                           ):%::       :::::;
                                       __,::%:(        :::::
                                    ,;:%%%%%%%:        ;:%::
                                      ;,--""-.`\  ,=--':%:%:\
                                     /"       "| /-".:%%%%%%%\
                                                     ;,-"'`)%%)   (CJ)
                                                    /"      "|

Documentation

Index

Constants

View Source
const ROLL_SIDES = 6

Variables

View Source
var (
	DefaultCanvas, DefaultCanvasError = NewCanvas(512, 512,
		float64(0.0), float64(1.0), float64(0.0), float64(1.0))
)

Functions

func BinarySearchRank

func BinarySearchRank(key int, a []int) int

func Draw

func Draw() error

func Gcd

func Gcd(p, q uint64) uint64

func Random

func Random() float64

func RandomUniform

func RandomUniform(min, max float64) float64

func ReadInts

func ReadInts(inbuf io.Reader) ([]int64, error)

func ThreeSumCount

func ThreeSumCount(a []int64) int64

Types

type Accumulator

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

func NewAccumulator

func NewAccumulator() *Accumulator

func (*Accumulator) AddDataValue

func (me *Accumulator) AddDataValue(val float64)

func (*Accumulator) Mean

func (me *Accumulator) Mean() float64

func (*Accumulator) String

func (me *Accumulator) String() string

type ArrayBag

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

func (*ArrayBag) Add

func (me *ArrayBag) Add(item interface{})

func (*ArrayBag) First

func (me *ArrayBag) First() IterableCursor

func (*ArrayBag) IsEmpty

func (me *ArrayBag) IsEmpty() bool

func (*ArrayBag) Size

func (me *ArrayBag) Size() int

type ArrayBagCursor

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

func (*ArrayBagCursor) Next

func (me *ArrayBagCursor) Next() IterableCursor

func (*ArrayBagCursor) Value

func (me *ArrayBagCursor) Value() reflect.Value

type ArrayQueue

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

func (*ArrayQueue) Dequeue

func (me *ArrayQueue) Dequeue() interface{}

func (*ArrayQueue) Enqueue

func (me *ArrayQueue) Enqueue(item interface{})

func (*ArrayQueue) First

func (me *ArrayQueue) First() IterableCursor

func (*ArrayQueue) IsEmpty

func (me *ArrayQueue) IsEmpty() bool

func (*ArrayQueue) Size

func (me *ArrayQueue) Size() int

type ArrayQueueCursor

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

func (*ArrayQueueCursor) Next

func (me *ArrayQueueCursor) Next() IterableCursor

func (*ArrayQueueCursor) Value

func (me *ArrayQueueCursor) Value() reflect.Value

type ArrayStack

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

func NewArrayStack

func NewArrayStack() *ArrayStack

func (*ArrayStack) First

func (me *ArrayStack) First() IterableCursor

func (*ArrayStack) IsEmpty

func (me *ArrayStack) IsEmpty() bool

func (*ArrayStack) Pop

func (me *ArrayStack) Pop() interface{}

func (*ArrayStack) Push

func (me *ArrayStack) Push(item interface{})

func (*ArrayStack) Size

func (me *ArrayStack) Size() int

type ArrayStackCursor

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

func (*ArrayStackCursor) Next

func (me *ArrayStackCursor) Next() IterableCursor

func (*ArrayStackCursor) Value

func (me *ArrayStackCursor) Value() reflect.Value

type Bag

type Bag interface {
	Iterable
	Add(item interface{})
}

func NewArrayBag

func NewArrayBag() Bag

func NewLinkedListBag

func NewLinkedListBag() Bag

type Canvas

type Canvas struct {
	Height int
	Width  int
	Xmin   float64
	Xmax   float64
	Ymin   float64
	Ymax   float64
	// contains filtered or unexported fields
}

func NewCanvas

func NewCanvas(height, width int, xmin, xmax, ymin, ymax float64) (*Canvas, error)

func (*Canvas) Bounds

func (me *Canvas) Bounds() image.Rectangle

func (*Canvas) Draw

func (me *Canvas) Draw() error

func (*Canvas) Image

func (me *Canvas) Image() *image.RGBA

func (*Canvas) Pixel

func (me *Canvas) Pixel(x, y float64) error

func (*Canvas) Rectangle

func (me *Canvas) Rectangle(x, y, halfWidth, halfHeight float64) error

type Counter

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

func NewCounter

func NewCounter(name string) *Counter

func Rolls

func Rolls(nrolls int) []*Counter

func (*Counter) Cmp

func (c *Counter) Cmp(other *Counter) int

func (*Counter) Increment

func (c *Counter) Increment()

func (*Counter) String

func (c *Counter) String() string

func (*Counter) Tally

func (c *Counter) Tally() int

type Date

type Date struct {
	Month int
	Day   int
	Year  int
}

func NewDate

func NewDate(m, d, y int) *Date

func (*Date) String

func (me *Date) String() string

type In

type In struct {
	Inbuf *bufio.Reader
	Fd    *os.File
}
var (
	Stdin *In
)

func NewIn

func NewIn(filename string) (*In, error)

func NewInFromReader

func NewInFromReader(inbuf io.Reader) *In

func (*In) IsEmpty

func (in *In) IsEmpty() bool

func (*In) ReadDouble

func (in *In) ReadDouble() (float64, error)

func (*In) ReadInt

func (in *In) ReadInt() (int64, error)

func (*In) ReadString

func (in *In) ReadString() (string, error)

type Interval1D

type Interval1D struct {
	Left  float64
	Right float64
}

func NewInterval1D

func NewInterval1D(left, right float64) *Interval1D

func (*Interval1D) Contains

func (me *Interval1D) Contains(x float64) bool

func (*Interval1D) Length

func (me *Interval1D) Length() float64

type Interval2D

type Interval2D struct {
	Xint   *Interval1D
	Yint   *Interval1D
	Canvas *Canvas
}

func NewInterval2D

func NewInterval2D(xint, yint *Interval1D, canvas *Canvas) *Interval2D

func (*Interval2D) Area

func (me *Interval2D) Area() float64

func (*Interval2D) Contains

func (me *Interval2D) Contains(p *Point2D) bool

func (*Interval2D) Draw

func (me *Interval2D) Draw()

type Iterable

type Iterable interface {
	First() IterableCursor
	IsEmpty() bool
	Size() int
}

type IterableCursor

type IterableCursor interface {
	Next() IterableCursor
	Value() reflect.Value
}

type LinkedListBag

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

func (*LinkedListBag) Add

func (me *LinkedListBag) Add(item interface{})

func (*LinkedListBag) First

func (me *LinkedListBag) First() IterableCursor

func (*LinkedListBag) IsEmpty

func (me *LinkedListBag) IsEmpty() bool

func (*LinkedListBag) Size

func (me *LinkedListBag) Size() int

type LinkedListBagCursor

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

func (*LinkedListBagCursor) Next

func (*LinkedListBagCursor) Value

func (me *LinkedListBagCursor) Value() reflect.Value

type LinkedListQueue

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

func (*LinkedListQueue) Dequeue

func (me *LinkedListQueue) Dequeue() interface{}

func (*LinkedListQueue) Enqueue

func (me *LinkedListQueue) Enqueue(item interface{})

func (*LinkedListQueue) First

func (me *LinkedListQueue) First() IterableCursor

func (*LinkedListQueue) IsEmpty

func (me *LinkedListQueue) IsEmpty() bool

func (*LinkedListQueue) Size

func (me *LinkedListQueue) Size() int

type LinkedListQueueCursor

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

func (*LinkedListQueueCursor) Next

func (*LinkedListQueueCursor) Value

func (me *LinkedListQueueCursor) Value() reflect.Value

type LinkedListStack

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

func NewLinkedListStack

func NewLinkedListStack() *LinkedListStack

func (*LinkedListStack) First

func (me *LinkedListStack) First() IterableCursor

func (*LinkedListStack) IsEmpty

func (me *LinkedListStack) IsEmpty() bool

func (*LinkedListStack) Pop

func (me *LinkedListStack) Pop() interface{}

func (*LinkedListStack) Push

func (me *LinkedListStack) Push(item interface{})

func (*LinkedListStack) Size

func (me *LinkedListStack) Size() int

type LinkedListStackCursor

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

func (*LinkedListStackCursor) Next

func (*LinkedListStackCursor) Value

func (me *LinkedListStackCursor) Value() reflect.Value

type Node

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

func (*Node) Value

func (me *Node) Value() reflect.Value

type Point2D

type Point2D struct {
	X float64
	Y float64
	// contains filtered or unexported fields
}

func NewPoint2D

func NewPoint2D(x, y float64, canvas *Canvas) *Point2D

func (*Point2D) Draw

func (me *Point2D) Draw()

type Queue

type Queue interface {
	Iterable
	Enqueue(item interface{})
	Dequeue() interface{}
}

func NewArrayQueue

func NewArrayQueue() Queue

func NewLinkedListQueue

func NewLinkedListQueue() Queue

type Stack

type Stack interface {
	Iterable
	Push(item interface{})
	Pop() interface{}
}

type Stopwatch

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

func NewStopwatch

func NewStopwatch() *Stopwatch

func (*Stopwatch) ElapsedTime

func (me *Stopwatch) ElapsedTime() time.Duration

Jump to

Keyboard shortcuts

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