ByteDurableDb.batch.build: def of mylsm-lsm-store@0.6.0.1 Import: import mylsm-lsm-store@0.6.0.1/src/ByteDurableDb.bend as ByteDurableDb Lines 1603-1637 of mylsm-lsm-store@0.6.0.1/src/ByteDurableDb.bend: https://jend.leeeet.dev/read.txt?path=mylsm-lsm-store@0.6.0.1/src/ByteDurableDb.bend&start_line=1603&end_line=1637 import Base import mylsm-lsm-store@0.6.0.1/src/ByteMemTable.bend as ByteMemTable import mylsm-lsm-store@0.6.0.1/src/ByteWal.bend as ByteWal def batch.build(fuel: Nat, state: BatchBuildState) -> ByteMemTable.Table & List<&1, ByteWal.Mutation>: match fuel: case 0n: match state: case BatchBuild{_, table, reversed}: (table, List.reverse(&1, ByteWal.Mutation, reversed)) case BatchBuildPut{_, _, _, table, reversed}: (table, List.reverse(&1, ByteWal.Mutation, reversed)) case BatchBuildDelete{_, _, table, reversed}: (table, List.reverse(&1, ByteWal.Mutation, reversed)) case 1n+rest: match state: case BatchBuild{mutations, table, reversed}: match mutations: case Nil{}: (table, List.reverse(&1, ByteWal.Mutation, reversed)) case Con{ByteWal.Put{key, value}, tail}: batch.build(rest, BatchBuildPut{ByteMemTable.bytes.clone(key), ByteMemTable.bytes.clone(value), tail, table, reversed}) case Con{ByteWal.Delete{key}, tail}: batch.build(rest, BatchBuildDelete{ByteMemTable.bytes.clone(key), tail, table, reversed}) case BatchBuildPut{keys, values, tail, table, reversed}: match keys: case (candidate_key, wal_key): match values: case (candidate_value, wal_value): batch.build(rest, BatchBuild{tail, ByteMemTable.put(table, candidate_key, candidate_value), Con{ByteWal.Put{wal_key, wal_value}, reversed}}) case BatchBuildDelete{keys, tail, table, reversed}: match keys: case (candidate_key, wal_key): batch.build(rest, BatchBuild{tail, ByteMemTable.del(table, candidate_key), Con{ByteWal.Delete{wal_key}, reversed}}) Uses (11): https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=List https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=List.reverse https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Nat https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Pair https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Sigma https://jend.leeeet.dev/definition.txt?path=mylsm-lsm-store@0.6.0.1/src/ByteDurableDb.bend&name=BatchBuildState https://jend.leeeet.dev/definition.txt?path=mylsm-lsm-store@0.6.0.1/src/ByteMemTable.bend&name=Table https://jend.leeeet.dev/definition.txt?path=mylsm-lsm-store@0.6.0.1/src/ByteMemTable.bend&name=bytes.clone https://jend.leeeet.dev/definition.txt?path=mylsm-lsm-store@0.6.0.1/src/ByteMemTable.bend&name=del https://jend.leeeet.dev/definition.txt?path=mylsm-lsm-store@0.6.0.1/src/ByteMemTable.bend&name=put https://jend.leeeet.dev/definition.txt?path=mylsm-lsm-store@0.6.0.1/src/ByteWal.bend&name=Mutation