HashFNV1a32 ( text ; empty )
Rate this function: Average rating: 4.4 (36 votes) Discuss this Custom Function
Vaughan Bromfield, Vaughan Bromfield Design
mailto:vbromfield@optusnet.com.au
Computes the 32 bit binary FNV1a has for the input text.
Sample Input:
HashFNV1a32 ( "contracts" ; "" ) 

Sample Output:
01011001111001011000000111111111 

Description:
HashFNV1a32 ( text ; empty )
The initial value for "empty" must be empty ("")
This function computes the 32bit binary hash for the input text based on the FNV1a algorithm
This function requires the following functions:
Bin2dec ( bin ; empty )
Dec2bin ( decimalNumber ; empty )
XORbin ( bin0 ; bin1 ; empty )
This custom function was written by Vaughan Bromfield <vbromfield@optusnet.com.au> on 14 March 2010.
This function is based on the algorithm published at:
http://www.isthe.com/chongo/tech/comp/fnv/index.html
http://en.wikipedia.org/wiki/Fowler_Noll_Vo_hash
Note: these functions are not guaranteed
or supported by BrianDunning.com. Please contact the individual
developer with any questions or problems.
This is my Custom Function and I want to
edit it
Discuss:Make a comment about this Custom Function (please try to keep it brief & to the point). Anyone can post:

Newest Custom Functions:
1. 
SortList ( theList ) 

(Sat, Jun 23, 8:45am) 
2. 
HexUUIDToNum_cf (_uuid) 

(Sat, Jun 16, 1:55pm) 
3. 
httpResponseCode ( responseHeaders ) 

(Tue, Jun 12, 10:40pm) 
4. 
FindDuplicateCharacters ( string ) 

(Fri, Jun 08, 5:01pm) 
5. 
FieldRepetitionLast ( field ; maxRepetition ) 

(Wed, Jun 06, 6:05pm) 
6. 
CountModifiedRecords ( NameTimestampField ; StartTimestamp ; EndTimestamp ) 

(Mon, May 28, 8:23am) 
7. 
JSONArrayLength ( JSONArrayStr ) 

(Fri, May 25, 7:46am) 
8. 
interpolation (y1; y2; y3; x1; x2; x3; x1y1; x2y1; x1y2; x2y2; rnd) 

(Sat, May 19, 3:55am) 


Here is an updated version of the function that uses a local variable instead of the second parameter. It should AFAIK produce the same results.

// HashFNV1a32 ( text )
//
// This function computes the 32bit binary hash
// for the input text based on the FNV1a algorithm
//
// This function requires the following functions:
// Bin2dec()
// Dec2bin()
// XORbin()
//
// This custom function was written by Vaughan Bromfield
// vbromfield@optusnet.com.au
// 14 March 2010
//
// This function is based on the algorithm published at:
// http://www.isthe.com/chongo/tech/comp/fnv/index.html
// http://en.wikipedia.org/wiki/Fowler_Noll_Vo_hash
//
// The local $variable is used to carry the result to the next recursion instead of a function parameter.
Case (
Length( text ) = 0 ;
Let( [ result = $_hash_HashFNV1a32 ; $_hash_HashFNV1a32 = "" ] ; result ) ; // return result, clear local variables
Let(
[
offset = 2166136261 ;
prime = 16777619 ;
chr = Right ( text ; 1 ) ;
nextxt = Left ( text ; Length( text )  1 ) ;
hash0 = If( IsEmpty( $_hash_HashFNV1a32 ) ; Dec2Bin( offset ) ; $_hash_HashFNV1a32 ) ;
hash1 = XORbin( hash0 ; Dec2Bin( Code( chr ) ) ) ;
$_hash_HashFNV1a32 = Right( "00000000000000000000000000000000" & Dec2Bin( Mod( Bin2Dec( hash1 ) * prime ; 4294967296 ) ) ; 32 )
] ;
HashFNV1a32 ( nextxt ) // recurse
) //end let
) //end case

Vaughan Bromfield, Sydney, Australia
August 26, 2010 6:12pm