MCPcopy Create free account
hub / github.com/DFHack/dfhack / fletcher16

Function fletcher16

plugins/remotefortressreader/remotefortressreader.cpp:307–324  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

305}
306
307uint16_t fletcher16(uint8_t const *data, size_t bytes)
308{
309 uint16_t sum1 = 0xff, sum2 = 0xff;
310
311 while (bytes) {
312 size_t tlen = bytes > 20 ? 20 : bytes;
313 bytes -= tlen;
314 do {
315 sum2 += sum1 += *data++;
316 } while (--tlen);
317 sum1 = (sum1 & 0xff) + (sum1 >> 8);
318 sum2 = (sum2 & 0xff) + (sum2 >> 8);
319 }
320 /* Second reduction step to reduce sums to 8 bits */
321 sum1 = (sum1 & 0xff) + (sum1 >> 8);
322 sum2 = (sum2 & 0xff) + (sum2 >> 8);
323 return sum2 << 8 | sum1;
324}
325
326void ConvertDfColor(int16_t index, RemoteFortressReader::ColorDefinition * out)
327{

Callers 5

CheckHashesFunction · 0.85
IsTiletypeChangedFunction · 0.85
IsDesignationChangedFunction · 0.85
IsspatterChangedFunction · 0.85
isItemChangedFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected