def route.need
mylsm-lsm-store@0.6.0.1 · src/scan/ByteBlockReader.bend:866
import mylsm-lsm-store@0.6.0.1/src/scan/ByteBlockReader.bend as ByteBlockReader
import Base
import mylsm-lsm-store@0.6.0.1/src/Fs.bend as Fs
import mylsm-lsm-store@0.6.0.1/src/scan/BlockRoutePolicy.bend as BlockRoutePolicy
import bend-kit-bytes@0.3.2.0/bytes.bend as Bytes
866def route.need(
867 file: File,
868 state: State,
869 +context: RouteContext,
870 key: Bytes.Bytes,
871 +search: BlockRoutePolicy.Search,
872 active: Bool
873) -> IO(RouteState):
874 match context:
875 case RouteContext{_, index_offset, _}:
876 match active:
877 case False{}:
878 IO.pure(RouteState, RouteSelect{Reader{file, state},
879 BlockRoutePolicy.selected_block(search)})
880 case True{}:
881 +mid = route.midpoint(search)
882 do IO<RouteState>:
883 raw : File & Result<&1, &1, U32 & String, Bytes.Bytes> <-
884 Fs.read_at(file, U32.from_nat(Nat.add(index_offset,
885 Nat.add(8n, Nat.mul(mid, 16n)))), 16)
886 return RouteRecordRead{
887 read_at.exact.pair(16, raw), state, context, key, search, mid}