<commit_before>/*
 * Copyright (C) 2014 <NAME> <<EMAIL>>
 */

#pragma once

#include <cassert>
#include <uavcan/stdint.hpp>
#include <uavcan/impl_constants.hpp>

namespace uavcan
{

/**
 * CRC-16-CCITT
 * Initial value: 0xFFFF
 * Poly: 0x1021
 * Reverse: no
 * Output xor: 0
 *
 * import crcmod
 * crc = crcmod.predefined.Crc('crc-ccitt-false')
 * crc.update('123456789')
 * crc.hexdigest()
 * '29B1'
 */
class UAVCAN_EXPORT TransferCRC
{
#if !UAVCAN_TINY
    static const uint16_t Table[256];
#endif

    uint16_t value_;

public:
    enum { NumBytes = 2 };

    TransferCRC()
        : value_(0xFFFF)
    { }

#if UAVCAN_TINY
    void add(uint8_t byte)
    {
        value_ ^= byte << 8;
        for (uint8_t bit = 8; bit > 0; --bit)
        {
            if (value_ & 0x8000)
            {
                value_ = (value_ << 1) ^ 0x1021;
            }
            else
            {
                value_ = (value_ << 1);
            }
        }
    }
#else
    void add(uint8_t byte)
    {
        value_ = ((value_ << 8) ^ Table[((value_ >> 8) ^ byte) & 0xFF]) & 0xFFFF;
    }
#endif

    void add(const uint8_t* bytes, unsigned len)
    {
        assert(bytes);
        while (len--)
        {
            add(*bytes++);
        }<commit_msg>Explicit cast in transport CRC computer<commit_after>/*
 * Copyright (C) 2014 <NAME> <<EMAIL>>
 */

#pragma once

#include <cassert>
#include <uavcan/stdint.hpp>
#include <uavcan/impl_constants.hpp>

namespace uavcan
{

/**
 * CRC-16-CCITT
 * Initial value: 0xFFFF
 * Poly: 0x1021
 * Reverse: no
 * Output xor: 0
 *
 * import crcmod
 * crc = crcmod.predefined.Crc('crc-ccitt-false')
 * crc.update('123456789')
 * crc.hexdigest()
 * '29B1'
 */
class UAVCAN_EXPORT TransferCRC
{
#if !UAVCAN_TINY
    static const uint16_t Table[256];
#endif

    uint16_t value_;

public:
    enum { NumBytes = 2 };

    TransferCRC()
        : value_(0xFFFF)
    { }

#if UAVCAN_TINY
    void add(uint8_t byte)
    {
        value_ ^= static_cast<uint16_t>(byte) << 8;
        for (uint8_t bit = 8; bit > 0; --bit)
        {
            if (value_ & 0x8000)
            {
                value_ = (value_ << 1) ^ 0x1021;
            }
            else
            {
                value_ = (value_ << 1);
            }
        }
    }
#else
    void add(uint8_t byte)
    {
        value_ = ((value_ << 8) ^ Table[((value_ >> 8) ^ byte) & 0xFF]) & 0xFFFF;
    }
#endif

    void add(const uint8_t* bytes, unsigned len)
    {
        assert(bytes);
        while (len--)
        {
            add(*bytes++);
        }
{'fraction_non_alphanumeric': 0.1412318556296587, 'fraction_numerical': 0.04550804236955669, 'mean_word_length': 1.8459821428571428, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2000123', 'n_tokens_mistral': 1042, 'n_tokens_neox': 939, 'n_words': 207}