implement Jenkins’ one-at-a-time hash, which has better avalanche
behaviour than DJB’s CDB hash (good if using more than one byte) and probably no funnels the CDB hash is good for short (5-6 char) ASCII keys though
This commit is contained in:
parent
fb6d8cd895
commit
4c1a99da7c
27
dot.mkshrc
27
dot.mkshrc
@ -1,4 +1,4 @@
|
||||
# $MirOS: src/bin/mksh/dot.mkshrc,v 1.46 2009/08/27 16:03:52 tg Exp $
|
||||
# $MirOS: src/bin/mksh/dot.mkshrc,v 1.47 2009/08/27 16:29:21 tg Exp $
|
||||
#-
|
||||
# Copyright (c) 2002, 2003, 2004, 2006, 2007, 2008, 2009
|
||||
# Thorsten Glaser <tg@mirbsd.org>
|
||||
@ -294,6 +294,31 @@ function Lcdbhash {
|
||||
Lcdbhash_add "$@"
|
||||
}
|
||||
|
||||
# Jenkins one-at-a-time hash (not via stdio, for speed)
|
||||
typeset -Z11 -Uui16 Loaathash_result
|
||||
function Loaathash_add {
|
||||
typeset u=$-
|
||||
set +U
|
||||
typeset s="$*"
|
||||
typeset -i i=0 n=${#s}
|
||||
|
||||
while (( i < n )); do
|
||||
((# Loaathash_result += 1#${s:(i++):1} ))
|
||||
((# Loaathash_result += Loaathash_result << 10 ))
|
||||
((# Loaathash_result ^= Loaathash_result >> 6 ))
|
||||
done
|
||||
|
||||
[[ $u = *U* ]] && set -U
|
||||
:
|
||||
}
|
||||
function Loaathash {
|
||||
Loaathash_result=0 # hmm...
|
||||
Loaathash_add "$@"
|
||||
((# Loaathash_result += Loaathash_result << 3 ))
|
||||
((# Loaathash_result ^= Loaathash_result >> 11 ))
|
||||
((# Loaathash_result += Loaathash_result << 15 ))
|
||||
}
|
||||
|
||||
# strip comments (and leading/trailing whitespace if IFS is set) from
|
||||
# any file(s) given as argument, or stdin if none, and spew to stdout
|
||||
function Lstripcom {
|
||||
|
Loading…
x
Reference in New Issue
Block a user