Download presentation

1
**New Go Programming Language by Google**

2
**Concurrent Programming**

3
Working Principle It works by taking a stream of all the natural numbers and introducing a sequence of filters one for each prime to winnow the multiples of that prime At each step we have a sequence of filters of the primes so far, and the next number to pop out is the next prime which triggers the creation of the next filter in the chain

4
Generate Function // Send the sequence 2, 3, 4, ... to channel 'ch'. Func generate(ch chan int) { for i := 2; ; i++ { ch <- i // Send 'i' to channel 'ch'. }

5
Filter Function func filter(in, out chan int, prime int) { for { i := <-in; // Receive value of new variable 'i' from 'in'. if i % prime != 0 { out <- i // Send 'i' to channel 'out'. }

6
Sieve Program func main() { ch := make(chan int); // Create a new channel. go generate(ch); // Start generate() as a goroutine. for { prime := <-ch; fmt.Println(prime); ch1 := make(chan int); go filter(ch, ch1, prime); ch = ch1 } }

Similar presentations

OK

Section 2.5 – Implicit Differentiation. Explicit Equations The functions that we have differentiated and handled so far can be described by expressing.

Section 2.5 – Implicit Differentiation. Explicit Equations The functions that we have differentiated and handled so far can be described by expressing.

© 2018 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Ppt on eddy current brakes ppt Ppt on area of a circle Ppt on the road not taken by frost Ppt on nature and history of democracy in nepal Ppt on microcontroller based digital thermometer Ppt on electrical appliances and their uses Ppt on event handling in javascript something happens Download ppt on dot net Ppt on formation of joint stock company Ppt on resume writing