def calculate_block
bend-edit-distance@0.2.2.0 · src/Myers.bend:94
import bend-edit-distance@0.2.2.0/src/Myers.bend as Myers
import Base
94
95
96def calculate_block(block: Block, +eq: U32, hin: Carry) -> Block & Carry:
97 Block{+pv, +mv, score} = block
98 Carry{hin_positive, +hin_negative} = hin
99 +xv = U32.or(eq, mv)
100 +eq_in = U32.or(eq, hin_negative)
101 +xh = (U32.xor(U32.add(U32.and(eq_in, pv), pv), pv) .|. eq_in : U32)
102 +ph = U32.or(mv, U32.not(U32.or(xh, pv)))
103 +mh = U32.and(pv, xh)
104 +hout_positive = U32.shrn(ph, 31n)
105 +hout_negative = U32.shrn(mh, 31n)
106 +ph_shifted = U32.or(U32.shl(ph), hin_positive)
107 mh_shifted = U32.or(U32.shl(mh), hin_negative)
108 next_pv = U32.or(mh_shifted, U32.not(U32.or(xv, ph_shifted)))
109 next_mv = U32.and(ph_shifted, xv)
110 (Block{next_pv, next_mv, U32.sub(U32.add(score, hout_positive), hout_negative)},
111 Carry{hout_positive, hout_negative})