def par_map.list.go

bend-kit-concurrency@0.2.0.0 · concurrency.bend:43

import bend-kit-concurrency@0.2.0.0/concurrency.bend as Concurrency
import Base

43# lr holds two halves of nl and nr elements. Depth d runs 2^(d+1) parallel parts.
44def par_map.list.go(
45  ~A: Type, ~B: Type, ~f: A -> B, d: Nat, +nl: Nat, +nr: Nat, lr: List<A> & List<A>
46) -> List<B>:
47  match d:
48    case 0n:
49      (l, r) = lr
50      lo hi = List.map(~A, ~B, ~f, l) List.map(~A, ~B, ~f, r)
51      List.append(&1, B, lo, hi)
52    case 1n+ +p:
53      (l, r) = lr
54      +hl = Nat.div(nl, 2n)
55      +hr = Nat.div(nr, 2n)
56      ls = split(A, l, hl)
57      rs = split(A, r, hr)
58      lo hi = par_map.list.go(~A, ~B, ~f, p, hl, Nat.sub(nl, hl), ls) par_map.list.go(~A, ~B, ~f, p, hr, Nat.sub(nr, hr), rs)
59      List.append(&1, B, lo, hi)

Uses (9)

Used by (1)