Packageorg.servebox.commons.utils.hash
Classpublic class StringHash

StringHash is an ActionScript version of the "General Purpose Hash Function Algorithms Library" by Arash Partow.



Public Methods
 MethodDefined by
  
APHash(str:String):int
[static] AP Hash algorithm.
StringHash
  
BKDRHash(str:String):int
[static] BKDR Hash algorithm.
StringHash
  
DEKHash(str:String):int
[static] DEK Hash algorithm.
StringHash
  
DJBHash(str:String):int
[static] DJB Hash algorithm.
StringHash
  
ELFHash(str:String):int
[static] ELF Hash algorithm.
StringHash
  
JSHash(str:String):int
[static] JS Hash algorithm.
StringHash
  
PJWHash(str:String):int
[static] PJW Hash algorithm.
StringHash
  
RSHash(str:String):int
[static] RS Hash algorithm.
StringHash
  
SDBMHash(str:String):int
[static] SDB Hash algorithm.
StringHash
Method detail
APHash()method
public static function APHash(str:String):int

AP Hash algorithm. An algorithm produced by Arash Partow. taking ideas from all of the above hash functions, making a hybrid rotative and additive hash function algorithm based around four primes 3,5,7 and 11. There isn't any real mathematical analysis explaining why one should use this hash function instead of the others described above other than the fact that Partow tried to resemble the design as close as possible to a simple LFSR. An empirical result which demonstrated the distributive abilities of the hash algorithm was obtained using a hash-table with 100003 buckets, hashing The Project Gutenberg Etext of Webster's Unabridged Dictionary, the longest encountered chain length was 7, the average chain length was 2, the number of empty buckets was 4579.

Parameters
str:String

Returns
int
BKDRHash()method 
public static function BKDRHash(str:String):int

BKDR Hash algorithm. This hash function comes from Brian Kernighan and Dennis Ritchie's book "The C Programming Language". It is a simple hash function using a strange set of possible seeds which all constitute a pattern of 31....31...31 etc, it seems to be very similar to the DJB hash function.

Parameters
str:String

Returns
int
DEKHash()method 
public static function DEKHash(str:String):int

DEK Hash algorithm. An algorithm proposed by Donald E. Knuth in The Art Of Computer Programming Volume 3, under the topic of sorting and search chapter 6.4.

Parameters
str:String

Returns
int
DJBHash()method 
public static function DJBHash(str:String):int

DJB Hash algorithm. An algorithm produced by Professor Daniel J. Bernstein and shown first to the world on the usenet newsgroup comp.lang.c. It is one of the most efficient hash functions ever published.

Parameters
str:String

Returns
int
ELFHash()method 
public static function ELFHash(str:String):int

ELF Hash algorithm. Similar to the PJW Hash function, but tweaked for 32-bit processors. Its the hash function widely used on most UNIX systems.

Parameters
str:String

Returns
int
JSHash()method 
public static function JSHash(str:String):int

JS Hash algorithm. A bitwise hash function written by Justin Sobel.

Parameters
str:String

Returns
int
PJWHash()method 
public static function PJWHash(str:String):int

PJW Hash algorithm. This hash algorithm is based on work by Peter J. Weinberger of AT&T Bell Labs.

Parameters
str:String

Returns
int
RSHash()method 
public static function RSHash(str:String):int

RS Hash algorithm. A simple hash function from Robert Sedgwicks Algorithms in C book. Partow added some simple optimizations to the algorithm in order to speed up its hashing process.

Parameters
str:String

Returns
int
SDBMHash()method 
public static function SDBMHash(str:String):int

SDB Hash algorithm. This is the algorithm of choice which is used in the open source SDBM project. The hash function seems to have a good over-all distribution for many different data sets. It seems to work well in situations where there is a high variance in the MSBs of the elements in a data set.

Parameters
str:String

Returns
int