various fixes and optimisations:
• ensure unsigned arithmetics is used in the cdb hash • make the hash functions print their result again • now we can use the Lb64{en,de}code trick of using stdin if "$*"=="" • optimise the one-at-a-time code for shell
This commit is contained in:
parent
4c1a99da7c
commit
b5b5d905b0
16
dot.mkshrc
16
dot.mkshrc
@ -1,4 +1,4 @@
|
||||
# $MirOS: src/bin/mksh/dot.mkshrc,v 1.47 2009/08/27 16:29:21 tg Exp $
|
||||
# $MirOS: src/bin/mksh/dot.mkshrc,v 1.48 2009/08/27 16:40:08 tg Exp $
|
||||
#-
|
||||
# Copyright (c) 2002, 2003, 2004, 2006, 2007, 2008, 2009
|
||||
# Thorsten Glaser <tg@mirbsd.org>
|
||||
@ -280,10 +280,11 @@ function Lcdbhash_add {
|
||||
typeset u=$-
|
||||
set +U
|
||||
typeset s="$*"
|
||||
[[ -n $s ]] || { s=$(cat;print x); s=${s%x}; }
|
||||
typeset -i i=0 n=${#s}
|
||||
|
||||
while (( i < n )); do
|
||||
(( Lcdbhash_result = (Lcdbhash_result * 33) ^ 1#${s:(i++):1} ))
|
||||
((# Lcdbhash_result = (Lcdbhash_result * 33) ^ 1#${s:(i++):1} ))
|
||||
done
|
||||
|
||||
[[ $u = *U* ]] && set -U
|
||||
@ -292,6 +293,7 @@ function Lcdbhash_add {
|
||||
function Lcdbhash {
|
||||
Lcdbhash_result=5381
|
||||
Lcdbhash_add "$@"
|
||||
print ${Lcdbhash_result#16#}
|
||||
}
|
||||
|
||||
# Jenkins one-at-a-time hash (not via stdio, for speed)
|
||||
@ -300,11 +302,12 @@ function Loaathash_add {
|
||||
typeset u=$-
|
||||
set +U
|
||||
typeset s="$*"
|
||||
[[ -n $s ]] || { s=$(cat;print x); s=${s%x}; }
|
||||
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 + 1#${s:(i++):1}) *
|
||||
1025 ))
|
||||
((# Loaathash_result ^= Loaathash_result >> 6 ))
|
||||
done
|
||||
|
||||
@ -315,8 +318,9 @@ function Loaathash {
|
||||
Loaathash_result=0 # hmm...
|
||||
Loaathash_add "$@"
|
||||
((# Loaathash_result += Loaathash_result << 3 ))
|
||||
((# Loaathash_result ^= Loaathash_result >> 11 ))
|
||||
((# Loaathash_result += Loaathash_result << 15 ))
|
||||
((# Loaathash_result = (Loaathash_result ^
|
||||
(Loaathash_result >> 11)) * 32769 ))
|
||||
print ${Loaathash_result#16#}
|
||||
}
|
||||
|
||||
# strip comments (and leading/trailing whitespace if IFS is set) from
|
||||
|
Loading…
x
Reference in New Issue
Block a user