Package: pyhash
Introductionpyhashis a python non-cryptographic hash library.It provides several common hash algorithms with C/C++ implementation for performance and compatibility.>>>importpyhash>>>hasher=pyhash.fnv1_32()>>>hasher('hello world')2805756500L>>>hasher('hello',' ','world')2805756500L>>>hasher('world',seed=hasher('hello '))2805756500LIt also can be used to generate fingerprints without seed.>>>importpyhash>>>fp=pyhash.farm_fingerprint_64()>>>fp('hello')>>>13009744463427800296L>>>fp('hello','world')>>>[13009744463427800296L,16436542438370751598L]Noteshasher('hello', ' ', 'world')is a syntax sugar forhasher('world', seed=hasher(' ', seed=hasher('hello'))), and may not equals tohasher('hello world'), because some hash algorithms use differenthashandseedsize.For example,metrohash always use 32bit seed for 64/128 bit hash value.>>>importpyhash>>>hasher=pyhash.metro_64()>>>hasher('hello world')>>>5622782129197849471L>>>hasher('hello',' ','world')>>>16402988188088019159L>>>hasher('world',seed=hasher(' ',seed=hasher('hello')))>>>16402988188088019159LInstallation$pipinstallpyhashNotesIfpipinstall failed with similar errors,#27/usr/lib/gcc/x86_64-linux-gnu/6/include/smmintrin.h:846:1: error: inlining failed in call to always_inline 'long long unsigned int _mm_crc32_u64(long long unsigned int, long long unsigned int)': target specific option mismatch
 _mm_crc32_u64 (unsigned long long __C, unsigned long long __V)
 ^~~~~~~~~~~~~
src/smhasher/metrohash64crc.cpp:52:34: note: called from here
             v[0] ^= _mm_crc32_u64(v[0], read_u64(ptr)); ptr += 8;
                     ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~Please upgradepipandsetuptoolsto latest version and try again$pipinstall--upgradepipsetuptoolsNotesIfpipinstall failed on MacOS with similar errors#28creating build/temp.macosx-10.6-intel-3.6
   ...
   /usr/bin/clang -fno-strict-aliasing -Wsign-compare -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -arch i386 -arch x86_64 -g -c src/smhasher/metrohash64crc.cpp -o build/temp.macosx-10.6-intel-3.6/src/smhasher/metrohash64crc.o -msse4.2 -maes -mavx -mavx2
    src/smhasher/metrohash64crc.cpp:52:21: error: use of undeclared identifier '_mm_crc32_u64'
                v[0] ^= _mm_crc32_u64(v[0], read_u64(ptr)); ptr += 8;
                        ^You may try to$CFLAGS="-mmacosx-version-min=10.13"pipinstallpyhashNotespyhashonly supportpypyv6.0 or newer, pleasedownload and installthe latestpypy.Algorithmspyhash supports the following hash algorithmsFNV(Fowler-Noll-Vo) hashfnv1_32fnv1a_32fnv1_64fnv1a_64MurmurHashmurmur1_32murmur1_aligned_32murmur2_32murmur2a_32murmur2_aligned_32murmur2_neutral_32murmur2_x64_64amurmur2_x86_64bmurmur3_32murmur3_x86_128murmur3_x64_128lookup3lookup3lookup3_littlelookup3_bigSuperFastHashsuper_fast_hashCity Hash_ city_32city_64city_128city_crc_128city_fingerprint_256Spooky Hashspooky_32spooky_64spooky_128FarmHashfarm_32farm_64farm_128farm_fingerprint_32farm_fingerprint_64farm_fingerprint_128MetroHashmetro_64metro_128metro_crc_64metro_crc_128MumHashmum_64T1Hat1ha2(64-bit little-endian)t1ha2_128(128-bit little-endian)t1ha1(64-bit native-endian)t1ha1_le(64-bit little-endian)t1ha1_be(64-bit big-endian)t1ha0(64-bit, choice fastest function in runtime.)t1_32t1_32_bet1_64t1_64_beXXHashxx_32xx_64String and Bytes literalsPython has two types can be used to present string literals, the hash values of the two types are definitely different.For Python 2.xString literals,strwill be used by default,unicodecan be used with theuprefix.For Python 3.xString and Bytes literals,unicodewill be used by default,bytescan be used with thebprefix.For example,$ python2
Python 2.7.15 (default, Jun 17 2018, 12:46:58)
[GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyhash
>>> hasher = pyhash.murmur3_32()
>>> hasher('foo')
4138058784L
>>> hasher(u'foo')
2085578581L
>>> hasher(b'foo')
4138058784L$ python3
Python 3.7.0 (default, Jun 29 2018, 20:13:13)
[Clang 9.1.0 (clang-902.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyhash
>>> hasher = pyhash.murmur3_32()
>>> hasher('foo')
2085578581
>>> hasher(u'foo')
2085578581
>>> hasher(b'foo')
4138058784You can also importunicode_literalsto use unicode literals in Python 2.xfrom__future__importunicode_literalsIn general, it is more compelling to use unicode_literals when back-porting new or existing Python 3 code to Python 2/3 than when porting existing Python 2 code to 2/3. In the latter case, explicitly marking up all unicode string literals with u'' prefixes would help to avoid unintentionally changing the existing Python 2 API. However, if changing the existing Python 2 API is not a concern, using unicode_literals may speed up the porting process.