Changeset 18188
- Timestamp:
- 06/01/15 11:52:48 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/tools.h
r15167 r18188 18 18 std::vector<std::string> Split(const std::string &, const std::string &); 19 19 std::string Uncomment(const std::string &opt); 20 21 template<typename T> 22 uint16_t Fletcher16(const T *t, size_t cnt) 23 { 24 const uint8_t *data = reinterpret_cast<const uint8_t*>(t); 25 26 size_t bytes = cnt*sizeof(T); 27 28 uint16_t sum1 = 0xff; 29 uint16_t sum2 = 0xff; 30 31 while (bytes) 32 { 33 size_t tlen = bytes > 20 ? 20 : bytes; 34 bytes -= tlen; 35 36 do { 37 sum2 += sum1 += *data++; 38 } while (--tlen); 39 40 sum1 = (sum1 & 0xff) + (sum1 >> 8); 41 sum2 = (sum2 & 0xff) + (sum2 >> 8); 42 } 43 44 // Second reduction step to reduce sums to 8 bits 45 sum1 = (sum1 & 0xff) + (sum1 >> 8); 46 sum2 = (sum2 & 0xff) + (sum2 >> 8); 47 48 return sum2 << 8 | sum1; 49 } 50 20 51 } 21 52
Note:
See TracChangeset
for help on using the changeset viewer.