master > master: codego rekursives Aufrufen mit Channels ausgelagert
This commit is contained in:
parent
8778d31676
commit
c10f194ce4
51
codego/aussagenlogik/rekursion/rekursion_aux.go
Normal file
51
codego/aussagenlogik/rekursion/rekursion_aux.go
Normal file
@ -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…
Reference in New Issue
Block a user