Browse Source

master > master: codego rekursives Aufrufen mit Channels ausgelagert

master
RD 1 year ago
parent
commit
c10f194ce4
  1. 51
      codego/aussagenlogik/rekursion/rekursion_aux.go

51
codego/aussagenlogik/rekursion/rekursion_aux.go

@ -0,0 +1,51 @@
package rekursion
import (
"logik/aussagenlogik/syntaxbaum"
)
/* ---------------------------------------------------------------- *
* EXPORTS
* ---------------------------------------------------------------- */
func RekursiveCallInt(fn func(ch chan int, tree syntaxbaum.SyntaxBaum), children []syntaxbaum.SyntaxBaum) []int {
subChannel := make(chan int)
values := make([]int, len(children))
// start parallel computations on subformulae
for _, subtree := range children {
go fn(subChannel, subtree)
}
// successively read values
for i := 0; i < len(children); i++ {
values[i] = <-subChannel
}
return values
}
func RekursiveCallString(fn func(ch chan string, tree syntaxbaum.SyntaxBaum), children []syntaxbaum.SyntaxBaum) []string {
subChannel := make(chan string)
values := make([]string, len(children))
// start parallel computations
for _, subtree := range children {
go fn(subChannel, subtree)
}
// successively read values
for i := 0; i < len(children); i++ {
values[i] = <-subChannel
}
return values
}
func RekursiveCallStringList(fn func(ch chan []string, tree syntaxbaum.SyntaxBaum), children []syntaxbaum.SyntaxBaum) [][]string {
subChannel := make(chan []string)
values := make([][]string, len(children))
// start parallel computations
for _, subtree := range children {
go fn(subChannel, subtree)
}
// successively read values
for i := 0; i < len(children); i++ {
values[i] = <-subChannel
}
return values
}
Loading…
Cancel
Save