Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Optimized CRC Computer

#include <boost/cstdint.hpp>  // for boost::uintmax_t
#include <cstddef>            // for std::size_t

namespace boost
{
    template < std::size_t Bits, uintmax_t TruncPoly, uintmax_t InitRem,
     uintmax_t FinalXor, bool ReflectIn, bool ReflectRem >
    class crc_optimal;
}

The boost::crc_optimal class template acts as an unaugmented-CRC processor that can accept input at the byte-level. It takes all the Rocksoft™ Model CRC Algorithm parameters as template parameters. Like in crc_basic, the WIDTH stays as the first parameter and determines the built-in unsigned integer type used for division registers. The other Rocksoft™ Model CRC Algorithm parameters move up to the template parameter field in the same relative order they were in the crc_basic constructor. (Some parameters have defaults.) Objects based from crc_optimal can either be default-constructed, giving it the same behavior as a crc_basic object with the equivalent settings, or use one parameter, which overrides the initial remainder value[2] without permanently affecting the initial-remainder attribute.

Besides template parameters and construction, crc_optimal differs from crc_basic interface-wise by:

The major difference between crc_basic and crc_optimal is the internals. Objects from crc_basic run their CRC algorithm one bit at a time, no matter which unit is used as input. Objects from crc_optimal, when WIDTH is at least CHAR_BIT[5], use a byte-indexed table-driven CRC algorithm which is a lot faster than processing individual bits.

Since all of the parameters are specified at compile-time, you cannot reuse a single computer object for separate runs with differing parameters. The type uses the automatically-defined copy/move/assign and destruction routines.



[2] i.e. The interim-remainder before any input is read.

[3] Like std::for_each.

[4] Albeit this object won't change its return value within code that only uses it as a generator.

[5] i.e. The optimizations are suspended if the WIDTH only justifies using part of a single byte.


PrevUpHomeNext