def packed.blocks

mylsm-lsm-store@0.6.0.1 · src/hub_sha/sha256.bend:73

import mylsm-lsm-store@0.6.0.1/src/hub_sha/sha256.bend as Sha256
import Base
import mylsm-lsm-store@0.6.0.1/src/hub_sha/state.bend as S
import bend-kit-bytes@0.3.2.0/bytes.bend as Packed

73# Read complete 64-byte blocks directly through a bounded package cursor.
74def packed.blocks(
75  remaining: Nat,
76  in_block: Nat,
77  pair: Packed.Cursor & Maybe<&2, U32>,
78  acc: List<&2, U32>,
79  state: S.State
80) -> Packed.Cursor & S.State:
81  match remaining:
82    case 0n:
83      match pair:
84        case (cursor, _):
85          (cursor, state)
86    case 1n:
87      match in_block:
88        case 0n:
89          match pair:
90            case (cursor, _):
91              (cursor, state)
92        case 1n:
93          match pair:
94            case (cursor, Some{word}):
95              (cursor, packed.compress(List.reverse(&2, U32, word <> acc), state))
96            case (cursor, None{}):
97              (cursor, state)
98        case 1n+more:
99          match pair:
100            case (cursor, _):
101              (cursor, state)
102    case 1n+more:
103      match in_block:
104        case 0n:
105          match pair:
106            case (cursor, _):
107              (cursor, state)
108        case 1n:
109          match pair:
110            case (cursor, Some{word}):
111              packed.blocks(more, 16n, Packed.Cursor.u32be(cursor), Nil{},
112                packed.compress(List.reverse(&2, U32, word <> acc), state))
113            case (cursor, None{}):
114              (cursor, state)
115        case 1n+left:
116          match pair:
117            case (cursor, Some{word}):
118              packed.blocks(more, left, Packed.Cursor.u32be(cursor), word <> acc, state)
119            case (cursor, None{}):
120              (cursor, state)

Uses (11)

Used by (2)