From fd0ddd5902f23ddd68f93604d5a7f689769c2d84 Mon Sep 17 00:00:00 2001 From: tg Date: Mon, 22 Jun 2009 17:38:39 +0000 Subject: [PATCH] =?UTF-8?q?add=20a=20DJB=20cdb=20hash=20implementation=20i?= =?UTF-8?q?n=20mksh,=20which,=20for=20speed,=20uses=20a=20global=20variabl?= =?UTF-8?q?e=20ipv=20print=E2=80=99ing=20the=20result=20for=20reparse.=20c?= =?UTF-8?q?onveniently,=20it=E2=80=99s=20already=20typeset=20just=20right?= =?UTF-8?q?=20(unsigned=20hex=20integer,=20zero=20padded)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dot.mkshrc | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/dot.mkshrc b/dot.mkshrc index 8532691..fdb37b7 100644 --- a/dot.mkshrc +++ b/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 # Thorsten Glaser @@ -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 # any file(s) given as argument, or stdin if none, and spew to stdout function Lstripcom {