http://qs1969.pair.com?node_id=134129

in reply to More Sorted Business with Hashes

The short answer is that you can't. The long answer deals with why you can't:

A 'hash function' reduces any input to a number within a given range. In most cases, this involves some kind of bit-twiddling:

```\$HASH_LIMIT = 1024;

##  myhash (key:string) : int
#
#   calculate a checksum
#
sub myhash {
my \$key = shift;
my \$h = 0;

for \$c (unpack ('c*', \$key)) {  ##  break the key into chars

\$h *= 2;            ##  shift the hash value left one bit
\$h ^= \$c;           ##  and XOR it with the next char
}

\$h %= \$HASH_LIMIT;      ##  trim to fit the defined range
return (\$h);            ##  and return the result
}

for \$k (qw( testing the hash function )) {
printf ("%10s - %s\n", \$k, &myhash(\$k));
}

A 'hash' is a data structure that stores values in an array, using the value returned by a hash function as an array index:

```@MY_HASH = (0) x \$HASH_LIMIT;

##  put (key:string, val:string) : nil
#
#   store a value in a hash
#
sub put {
my \$key = shift;
my \$val = shift;

\$MY_HASH[ &myhash(\$key) ] = \$val;
return;
}

##  get (key:string) : string
#
#   get a value from the hash
#
sub get {
my \$key = shift;

return (\$MY_HASH[ &myhash(\$key) ]);
}