add a DJB cdb hash implementation in mksh, which, for speed, uses a
global variable ipv print’ing the result for reparse. conveniently, it’s already typeset just right (unsigned hex integer, zero padded)
This commit is contained in:
parent
261cabad23
commit
fd0ddd5902
23
dot.mkshrc
23
dot.mkshrc
@ -1,4 +1,4 @@
|
|||||||
# $MirOS: src/bin/mksh/dot.mkshrc,v 1.44 2009/06/22 17:27:22 tg Exp $
|
# $MirOS: src/bin/mksh/dot.mkshrc,v 1.45 2009/06/22 17:38:39 tg Rel $
|
||||||
#-
|
#-
|
||||||
# Copyright (c) 2002, 2003, 2004, 2006, 2007, 2008, 2009
|
# Copyright (c) 2002, 2003, 2004, 2006, 2007, 2008, 2009
|
||||||
# Thorsten Glaser <tg@mirbsd.org>
|
# Thorsten Glaser <tg@mirbsd.org>
|
||||||
@ -274,6 +274,27 @@ function Lb64encode {
|
|||||||
:
|
:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# DJB cdb hash (not via stdio, for speed)
|
||||||
|
typeset -Z11 -Uui16 Lcdbhash_result
|
||||||
|
function Lcdbhash_add {
|
||||||
|
typeset u=$-
|
||||||
|
set +U
|
||||||
|
typeset s="$*"
|
||||||
|
typeset -i i=0 n=${#s}
|
||||||
|
|
||||||
|
while (( i < n )); do
|
||||||
|
(( Lcdbhash_result = ((Lcdbhash_result << 5) + \
|
||||||
|
Lcdbhash_result) ^ 1#${s:(i++):1} ))
|
||||||
|
done
|
||||||
|
|
||||||
|
[[ $u = *U* ]] && set -U
|
||||||
|
:
|
||||||
|
}
|
||||||
|
function Lcdbhash {
|
||||||
|
Lcdbhash_result=5381
|
||||||
|
Lcdbhash_add "$@"
|
||||||
|
}
|
||||||
|
|
||||||
# strip comments (and leading/trailing whitespace if IFS is set) from
|
# 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
|
# any file(s) given as argument, or stdin if none, and spew to stdout
|
||||||
function Lstripcom {
|
function Lstripcom {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user