traversal_partition.bend

stelliferous@0.0.3.0 · 13 lines · 0 definitions

1# A work partition is independent of its element representation and ownership.
2# Storage remains in the leaf payload; offset/span describe its logical range.
3import Base
4
5type Tree<ownership,-Block: Kind(ownership),-Details: Data> is Kind(ownership):
6  Leaf{data: Block,offset: U32,span: U32,details: Details}
7  Fork{left: Tree<ownership,Block,Details>,right: Tree<ownership,Block,Details>}
8
9def gather(~ownership: Quant,~Output: Kind(ownership),~copy: U32 -> U32 -> U32 -> U32 -> Output -> Output -> Output,
10  partitions: Tree<ownership,Output,U32>,output: Output,+positions: U32) -> Output:
11  match partitions:
12    case Leaf{input,offset,span,rows}: copy(rows,offset,positions,span,input,output)
13    case Fork{left,right}: gather(~ownership,~Output,~copy,right,gather(~ownership,~Output,~copy,left,output,positions),positions)