Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Hash an expression using Fowler-Noll-Vo hashing
ResourceFunction["FowlerNollVoHash"][expr] gives the Fowler-Noll-Vo (FNV) hash code for the expression expr. | |
ResourceFunction["FowlerNollVoHash"][expr,n] gives the n-bit hash. |
The 32-bit FNV-1a hash of a string:
In[1]:= |
![]() |
Out[1]= |
![]() |
Use 64 bits:
In[2]:= |
![]() |
Out[2]= |
![]() |
64-bit FNV-1a hash of a long string:
In[3]:= |
![]() |
Out[3]= |
![]() |
Display in hexadecimal format:
In[4]:= |
![]() |
Out[4]= |
![]() |
Use ByteArray to hash literal bytes:
In[5]:= |
![]() |
Out[5]= |
![]() |
An equivalent specification:
In[6]:= |
![]() |
Out[6]= |
![]() |
Hash a file:
In[7]:= |
![]() |
Out[7]= |
![]() |
Hash a general expression:
In[8]:= |
![]() |
Out[8]= |
![]() |
Do not use the "alternate" method for FNV hashing:
In[9]:= |
![]() |
Out[9]= |
![]() |
Set "UseShift"→False to avoid using a shift when hashing. Not using a shift may lead to more hash collisions:
In[10]:= |
![]() |
Out[10]= |
![]() |
Provide a "checksum" to validate data integrity:
In[11]:= |
![]() |
Out[12]= |
![]() |
Change some of the data:
In[13]:= |
![]() |
The checksum has changed:
In[14]:= |
![]() |
Out[14]= |
![]() |
In[15]:= |
![]() |
Out[15]= |
![]() |
A string that gives a 64-bit FNV-1a hash of 0:
In[16]:= |
![]() |
Out[16]= |
![]() |
A string that gives a 32-bit FNV-1 hash of 0:
In[17]:= |
![]() |
Out[17]= |
![]() |
This work is licensed under a Creative Commons Attribution 4.0 International License