A distributed KV store keeps every stripe of cache as 10 data chunks plus 2 parity chunks on 12 nodes, and can rebuild the stripe from any 10 of them. Implement a Reed-Solomon style code over the prime field : the data symbols at each position are the coefficients of a polynomial, and chunk holds that polynomial evaluated at .
encode_stripe(data, n=12)
data is an integer array of shape (k, m): k data chunks of m symbols each, every symbol in 0..255. Return an (n, m) integer array where row j holds, for each column, .decode_stripe(chunks, k=10)
chunks is a list of length n whose entries are either a 1-D array (the chunk survived) or None (the node failed). If fewer than k chunks survive, return None. Otherwise use the first k surviving chunks (lowest indices) and recover the (k, m) data array exactly: solve the Vandermonde system modulo 257.usable_fraction(n, k)
k / n rounded to 4 decimals, the share of raw capacity that holds data.pow(a, 255, 257) is the inverse of a by Fermat's little theorem.int64 is enough.k distinct points give an invertible system; verify by decoding from the parity rows alone.