NLinker

Untitled

Jun 11th, 2020
1,313
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package main
  2.  
  3. func main() {}
  4.  
  5. func Merge2Channels(f func(int) int, in1 <-chan int, in2 <-chan int, out chan<- int, n int) {
  6.   go func() {
  7.     ww1 := make(chan chan int, n)
  8.     ww2 := make(chan chan int, n)
  9.  
  10.     go func() {
  11.       for i := 0; i < n; i++ {
  12.         f1 := <-<-ww1
  13.         f2 := <-<-ww2
  14.         out <- f1 + f2
  15.       }
  16.     }()
  17.  
  18.     input := func(in <-chan int, ww chan chan int) {
  19.       for i := 0; i < n; i++ {
  20.         w := make(chan int)
  21.         ww <- w
  22.         x := <-in
  23.         go func(w chan int, x int) { w <- f(x) }(w, x)
  24.       }
  25.     }
  26.  
  27.     go input(in1, ww1)
  28.     go input(in2, ww2)
  29.   }()
  30. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×