def page.build.go
mylsm-lsm-store@0.6.0.1 · src/ByteSstFile.bend:430
import mylsm-lsm-store@0.6.0.1/src/ByteSstFile.bend as ByteSstFile
import Base
import mylsm-lsm-store@0.6.0.1/src/ByteMemTable.bend as ByteMemTable
import mylsm-lsm-store@0.6.0.1/src/scan/ByteBlockBuilder.bend as ByteBlockBuilder
430def page.build.go(
431 fuel: Nat,
432 builder: PageBuild,
433 pending: List<&1, ByteMemTable.Entry> & ByteBlockBuilder.Decision,
434 +max_bytes: Nat
435) -> Result<&1, &1, Error, PagePlan>:
436 match fuel:
437 case 0n:
438 match builder:
439 case PageBuild{current, _, _, completed, completed_count}:
440 match pending:
441 case (Nil{}, _):
442 Done{page.finish(completed, current, completed_count)}
443 case _: Fail{TooLarge{}}
444 case 1n+rest:
445 match builder:
446 case PageBuild{current, current_bytes, +current_count, completed,
447 completed_count}:
448 match pending:
449 case (Nil{}, _):
450 Done{page.finish(completed, current, completed_count)}
451 case (Con{entry, tail}, decision):
452 match decision:
453 case ByteBlockBuilder.RecordTooLarge{}: Fail{TooLarge{}}
454 case ByteBlockBuilder.Append{+used_bytes}:
455 page.build.go(rest,
456 PageBuild{Con{entry, current}, used_bytes,
457 Nat.add(current_count, 1n), completed, completed_count},
458 page.next.prepare(tail, Nat.add(current_count, 1n), used_bytes,
459 max_bytes), max_bytes)
460 case ByteBlockBuilder.StartNextBlock{+record_bytes}:
461 page.build.go(rest,
462 page.rollover(entry, current, completed, completed_count,
463 record_bytes),
464 page.next.prepare(tail, 1n, record_bytes, max_bytes), max_bytes)