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.