Documentation ¶
Index ¶
- func Crawl(url string, depth int, f *F, wg *sync.WaitGroup, fetcher Fetcher)
- func Fibonacci() func() int
- func Pic(dx, dy int) [][]uint8
- func Same(t1, t2 *tree.Tree) bool
- func Walk(t *tree.Tree, ch chan int)
- func WordCount(s string) map[string]int
- type F
- type Fetcher
- type IPAddr
- type Image
- type Iterator
- type MyReader
- type Newton
- type Optimiser
- type Rot13Reader
- type SqrtFuncDecorated
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Crawl ¶
Crawl recursively crawls url to a maximum of depth. The caller has to provide a lockable map *F, that keeps track of scanned urls, a wait group *sync.Waitgroup to count goroutines, and an implementation of the Fetcher interface. Crawl fetches urls concurrently and skips previously fetched urls in case of duplicates. The caller is responsible for waiting until the goroutines return.
func Fibonacci ¶
func Fibonacci() func() int
Fibonacci returns a closure that computes the next Fibonacci number with every subsequent call.
func Pic ¶
Pic returns png encoded data with an IMAGE tag that get parsed by the Go playground. https://play.golang.org/p/blLJbY6bFq It remains untested here.
func Same ¶
Same compares two trees for equality in the manner of reflect.DeepEqual. It converts trees to flat strings for comparison, which is not elegant but functional.
Types ¶
type F ¶
type F struct {
// contains filtered or unexported fields
}
F is a lockable map that has to be provided to Crawl to cache fetched urls.
type Fetcher ¶
type Fetcher interface { // Fetch returns the body of URL and a slice of URLs found on that page. Fetch(url string) (body string, urls []string, err error) }
Fetcher abstracts the fetch method provided to Crawl.
type Image ¶
type Image struct { }
Image implements the Image interface. Playground https://play.golang.org/p/wumbYwlBFl. Remains untested here.
func (Image) ColorModel ¶
ColorModel returns an RBGA color model.
type Iterator ¶
type Iterator int
Iterator sets the number of iterations for the Newton square root calculation.
type MyReader ¶
type MyReader struct {
// contains filtered or unexported fields
}
MyReader provides a reader to an embedded string.
type Newton ¶
type Newton interface {
// contains filtered or unexported methods
}
Newton is an exported interface that has a sqrter
type Optimiser ¶
type Optimiser float64
Optimiser sets the optimisation criteria for which the iterative Newton square root calculation stops.
type Rot13Reader ¶
type Rot13Reader struct {
// contains filtered or unexported fields
}
Rot13Reader provides methods to decode a rot13 encoded string to io.Reader
func (*Rot13Reader) Read ¶
func (r13 *Rot13Reader) Read(p []byte) (i int, err error)
Decode method for a Rot13Reader returning the decoded string.
func (*Rot13Reader) String ¶
func (r13 *Rot13Reader) String() string
String method for a Rot13Reader returning the undecoded string.
type SqrtFuncDecorated ¶
SqrtFuncDecorated is the exported type for an error decorated square root function defined as func(float64)(float64, int).
func NewSqrtFuncDecorator ¶
func NewSqrtFuncDecorator(f func(float64) (float64, int)) SqrtFuncDecorated
NewSqrtFuncDecorator is a constructor for a decorated square root function func(float64) (floa64, int).
Source Files ¶
- exercise-01-loops-and-functions.go
- exercise-02-slices.go
- exercise-03-maps-wordcount.go
- exercise-04-fibonacci-closures.go
- exercise-05-stringers.go
- exercise-06-errors.go
- exercise-07-readers.go
- exercise-08-rot13-reader.go
- exercise-09-images.go
- exercise-10-equivalent-binary-trees.go
- exercise-11-web-crawler.go