Example of how C ++ library boost performs CRC64 computing

Source: Internet
Author: User

Because of the platform access, the platform provides a string key as the user ID, and distributed is required, so the user ID cannot be incremental with the previous database, therefore, CRC64 is used to generate uint64_t as the user ID, which is also relatively simple. As follows:

The code is as follows: Copy code
Std: map <size_t, size_t> xLongMap;

Char szTemp [128] = {0 };

Boost: crc_optimal <64, 0x04C11DB7, 0, 0, false, false> crc;
For (uint32_t I = 0; I <1000000000; ++ I)
 {
Memset (szTemp, 0, sizeof (szTemp ));
Sprintf_s (szTemp, "% d % s", I, "1a2b3c", "4d5e6f", "7g8h9i ");
    
Crc. process_bytes (szTemp, strlen (szTemp ));
Size_t nPos = crc. checksum ();
Crc. reset ();

If (! XLongMap. insert (std: map <size_t, size_t >:: value_type (nPos, 0). second)
     {
Std: cout <"repeated, current quantity:" <I <", string:" <szTemp <", hash pos: "<nPos <std: endl;
System ("pause ");
Break;
     }
 }


Must contain boost/crc. hpp

In the test, there were no duplicates in 0.13 billion, which was quite powerful.

Unfortunately, this algorithm is not used later, because the key contains URL escape, resulting in % such characters, and other methods are used later.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.