As a pythonista one thing that struck me in the code fragments is zeroes and ones appearing everywhere. It looks very easy to have off by one errors. (It is very rare to have off by one errors in Python due to the way counting and ranges work.)
proc createCRCTable(): array[256, CRC32] =
for i in 0..255:
You can write: proc createCRCTable(): array[256, CRC32] =
for i in result.low .. result.high:
Or: proc createCRCTable(): array[256, CRC32] =
for i, v in result: # index, value
Or define your own indices iterator: iterator indices(x) =
for i in x.low .. x.high:
yield i
proc createCRCTable(): array[256, CRC32] =
for i in result.indices:
I think I should propose adding indices to the standard library.Python solves this by always starting from zero, and crucially not including the final number - ie range(0,3) gives 0, 1, 2 (no 3). You can also do negative indexing to count from the end - eg range(0, 3)[-1] gives the last element (2). The right thing happens when you mix the length of things into the arithmetic too - eg range(0, len(item)).