diff options
author | Joe Hunkeler <jhunkeler@gmail.com> | 2015-08-11 16:51:37 -0400 |
---|---|---|
committer | Joe Hunkeler <jhunkeler@gmail.com> | 2015-08-11 16:51:37 -0400 |
commit | 40e5a5811c6ffce9b0974e93cdd927cbcf60c157 (patch) | |
tree | 4464880c571602d54f6ae114729bf62a89518057 /sys/symtab/sthash.x | |
download | iraf-osx-40e5a5811c6ffce9b0974e93cdd927cbcf60c157.tar.gz |
Repatch (from linux) of OSX IRAF
Diffstat (limited to 'sys/symtab/sthash.x')
-rw-r--r-- | sys/symtab/sthash.x | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/sys/symtab/sthash.x b/sys/symtab/sthash.x new file mode 100644 index 00000000..c9cd00b9 --- /dev/null +++ b/sys/symtab/sthash.x @@ -0,0 +1,37 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +define MAX_HASHCHARS 18 + +# STHASH -- Compute the hash index of a key, i.e., the index of a thread in +# the symbol table index. Multiple keys may hash to the same thread. The +# ideal hash function will uniformly map keys into index space, both when the +# keys are selected randomly and when the keys form patterns, e.g., when keys +# share a common prefix. The SYMTAB package uses a simple hash function which +# is computed inline. The STHASH function is NOT used at present, but is +# included in the library anyway for use in other packages and because this +# is a slightly better (more uniform) hashing function than the simple inline +# version used in SYMTAB. + +int procedure sthash (key, modulus) + +char key[ARB] # character string serving as a key +int modulus # number of possible output values + +int i +long sum +int primes[MAX_HASHCHARS] +data (primes(i),i=1,9) /101,103,107,109,113,127,131,137,139/ +data (primes(i),i=10,18) /149,151,157,163,167,173,179,181,191/ + +begin + sum = 0 + + # Hash up to len(primes)=18 characters from the key. + do i = 1, MAX_HASHCHARS { + if (key[i] == EOS) + break + sum = sum + (key[i] * primes[i]) + } + + return (mod (sum, modulus) + 1) +end |