{
const testBlocks = Array.from({length: 256}, i => new Uint8Array([i, i, i, i, i, i, i, i]))
let res = []
let tbl = `
The following table shows the overhead for values of c and delta for a message of 256 blocks.
c is a free parameter, delta is the bound on decoding failing after Z packets have been recieved.
In the table, overhead is the mean extra fraction of packets needed to decode.
| c\\delta | 0.9 | 0.5 | 0.1 |
| ---- | ---- | --- | --- |
`
for(let c of [0.5, 0.1, 0.03, 0.01]) {
let reses = []
for(let delta of [0.9, 0.5, 0.1]) {
let packetsSamples = []
let Z_p
for(let i = 0; i < 10; i++) {
const [cdf, Z] = rsdCDF(testBlocks.length, c, delta)
Z_p = Z
const firstBlock = getEncodedBlock(testBlocks, cdf)
let decoded = Array.from({length:firstBlock.len}, () => undefined)
let holdingArea = Array.from({length: firstBlock.len}, () => undefined)
let packets = 1
let remainingBlocks = firstBlock.len
remainingBlocks -= decodeSingleBlock(firstBlock, decoded, holdingArea)
while(remainingBlocks > 0) {
packets++
remainingBlocks -= decodeSingleBlock(getEncodedBlock(testBlocks, cdf), decoded, holdingArea)
}
for(let i = 0; i < 256; i++) {
for(let j = 0; j < testBlocks[i].length; j++) {
if(decoded[i][j] != testBlocks[i][j]) {
return 'error: decoded output doesn\'t match input'
}
}
}
packetsSamples.push(packets)
}
const overhead = (packetsSamples.reduce((x, y) => x + y, 0.0) / packetsSamples.length) / 256
reses.push(`Z:${Z_p.toFixed(3)}, overhead:${overhead.toFixed(3)}`)
}
tbl = tbl + `|${c}|` + reses.join('|') + '|\n'
res.push(reses)
}
return md`${tbl}`
}