HashFNV1a32 ( text ; empty )
Rate this function: Average rating: 4.1 (7 votes) Discuss this Custom Function
Vaughan Bromfield, Vaughan Bromfield Design
mailto:vbromfield@optusnet.com.au
Computes the 32 bit binary FNV-1a 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 32-bit binary hash for the input text based on the FNV-1a 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. |
phpArrayValue ( array ; key ; pos ) |
| |
(Fri, Jan 27, 1:49pm) |
| 2. |
solfm_timeToMinutes (theTime;roundSec) |
| |
(Fri, Jan 20, 6:26am) |
| 3. |
filterLines(filterField;filterValue;Result) |
| |
(Sat, Jan 14, 2:20pm) |
| 4. |
getMaxValue ( theList ) |
| |
(Thu, Jan 12, 1:06pm) |
| 5. |
MiddleWordsIncPunct ( text ; startingWord ; numberOfWords ) |
| |
(Sat, Jan 07, 9:16am) |
| 6. |
WindowInfo |
| |
(Fri, Jan 06, 12:39pm) |
| 7. |
CenterWindow in Window vert horiz (demension) |
| |
(Fri, Jan 06, 12:25pm) |
| 8. |
UTF8_to_TXT ( Text , Platform ) |
| |
(Wed, Dec 28, 10:44pm) |
 |
|
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 32-bit binary hash
// for the input text based on the FNV-1a 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