def blocks.collect.go

mylsm-lsm-store@0.6.0.1 · src/ByteSstFile.bend:676

import mylsm-lsm-store@0.6.0.1/src/ByteSstFile.bend as ByteSstFile
import Base
import bend-kit-bytes@0.3.2.0/bytes.bend as Bytes

676def blocks.collect.go(
677  fuel: Nat,
678  fits: Bool,
679  remaining: List<&1, EncodedBlock>,
680  parts: List<&1, Bytes.Bytes>,
681  checksums: List<&1, Bytes.Bytes>,
682  index_entries: List<&1, Bytes.Bytes>,
683  separators: List<&1, Bytes.Bytes>,
684  +offset: Nat,
685  +separator_offset: Nat,
686  block_count: U32,
687  entry_count: U32
688) -> Result<&1, &1, Error, BlocksCollected>:
689  match fuel:
690    case 0n:
691      match fits:
692        case False{}: Fail{TooLarge{}}
693        case True{}:
694          match remaining:
695            case Nil{}:
696              +count = U32.to_nat(block_count)
697              Done{BlocksCollected{
698                Bytes.concat(List.reverse(&1, Bytes.Bytes, parts)),
699                Bytes.concat(List.reverse(&1, Bytes.Bytes, checksums)),
700                Bytes.concat([index.magic(), u32.bytes(U32.from_nat(count)),
701                  Bytes.concat([Bytes.concat(List.reverse(&1, Bytes.Bytes,
702                    index_entries)), Bytes.concat(List.reverse(&1, Bytes.Bytes,
703                    separators))])]),
704                U32.from_nat(count), entry_count}}
705            case _: Fail{Malformed{}}
706    case 1n+rest:
707      match fits:
708        case False{}: Fail{TooLarge{}}
709        case True{}:
710          match remaining:
711            case Nil{}:
712              +count = U32.to_nat(block_count)
713              Done{BlocksCollected{
714                Bytes.concat(List.reverse(&1, Bytes.Bytes, parts)),
715                Bytes.concat(List.reverse(&1, Bytes.Bytes, checksums)),
716                Bytes.concat([index.magic(), u32.bytes(U32.from_nat(count)),
717                  Bytes.concat([Bytes.concat(List.reverse(&1, Bytes.Bytes,
718                    index_entries)), Bytes.concat(List.reverse(&1, Bytes.Bytes,
719                    separators))])]),
720                U32.from_nat(count), entry_count}}
721            case Con{EncodedBlock{bytes, +byte_length, checksum, count,
722                separator, +separator_length}, tail}:
723              +length_nat = U32.to_nat(byte_length)
724              +separator_length_nat = U32.to_nat(separator_length)
725              blocks.collect.go(rest,
726                fits && Nat.is_le(Nat.add(offset, length_nat), 4294967295n) &&
727                  Nat.is_le(Nat.add(separator_offset, separator_length_nat),
728                    4294967295n), tail, Con{bytes, parts},
729                Con{checksum, checksums},
730                Con{Bytes.concat([u32.bytes(U32.from_nat(offset)),
731                  u32.bytes(byte_length),
732                  u32.bytes(U32.from_nat(separator_offset)),
733                  u32.bytes(separator_length)]), index_entries},
734                Con{separator, separators}, Nat.add(offset, length_nat),
735                Nat.add(separator_offset, separator_length_nat),
736                (block_count + 1 : U32), (entry_count + count : U32))

Uses (19)

Used by (1)