//! Returns crc32 of buffer[0, length); crc32_t crc32(const void* buffer, unsigned int length) { static boost::crc_32_type crc32_calculator; crc32_calculator.reset(); crc32_calculator.process_bytes(buffer, length); return crc32_calculator.checksum(); }
/** * 检查crc */ bool operator()( uint32_t aicrc_values, const char* aibuf , size_t aisize) { m_result.reset(); m_result.process_bytes( aibuf , aisize ); /** std::cout << "crc:[" << aicrc_values <<"]["<< m_result.checksum() << "]" << std::endl; */ return ( aicrc_values == m_result.checksum() ? true : false ); }
// A CRC-32 computer based on crc_optimal, for timing inline boost::uint32_t optimal_crc32 ( void const * buffer, std::size_t byte_count ) { static boost::crc_32_type computer; computer.reset(); computer.process_bytes( buffer, byte_count ); return computer.checksum(); }
void CLine::hash_string(const std::_tstring & s) { // Calc Hash boost::crc_32_type computer; computer.reset(); computer.process_bytes(s.c_str(), sizeof(TCHAR) * s.length()); m_hash = computer.checksum(); // Calc Anchor Hash bool prevIsGraph = true; static boost::crc_32_type anchorComputer; anchorComputer.reset(); for (unsigned int i = 0; i < s.length(); ++i) { bool isGraph = iswgraph(s[i]) != 0 || s[i] == '\r' || s[i] == '\n'; if (isGraph) anchorComputer.process_bytes(&s[i], sizeof(TCHAR)); prevIsGraph = isGraph; } m_anchorHash = anchorComputer.checksum(); }
/** * 生成 */ uint32_t operator()( const char* aibuf , size_t aisize) { m_result.reset(); m_result.process_bytes( aibuf , aisize ); return m_result.checksum(); }
{ boost::hash<std::string> string_hash; return string_hash(s); } void testForEach() { static std::string ar[] = {"one", "another", "last"}; BOOST_FOREACH(const std::string& s, ar) { std::cout << s << std::endl; } std::string s = "Hello0"; boost::crc_32_type result; result.process_bytes(s.data(), s.length()); unsigned tag = result.checksum(); std::cout << tag << std::endl; std::cout << abs(hashCode("32521001fffddf4425643d3e7fe")) << std::endl; std::cout << hashCode("1001") << std::endl; std::cout << hashCode("1001") << std::endl; //std::cout << boost::lexical_cast<int32_t>( "3669185006" ); unsigned int nId = 0; unsigned int progId = 0; std::stringstream ss; ss << std::hex << "A"; ss >> progId;
uint32_t GetCrc32(boost::crc_32_type crc, string& s) { crc.process_bytes(s.data(), s.length()); cout << crc.checksum() << endl; return crc.checksum(); }
//------------------------------------------------------------------------ // inline void jpeg_encoder_impl::calc_crc_(core::jpeg_data_t& jpegdata) { crc_result.reset(); crc_result.process_bytes( jpegdata.data.get(), jpegdata.size); jpegdata.crc =crc_result.checksum(); }