X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fjenkins_hash.c;fp=src%2Fjenkins_hash.c;h=1f0cd8b127282680037ca846347f724c854e4542;hb=85a4a8d3f48c3d2c95efb6437b25f0804d966161;hp=0000000000000000000000000000000000000000;hpb=096341d55d0f82fbfdf4c1389c2216c368d385f3;p=pazpar2-moved-to-github.git diff --git a/src/jenkins_hash.c b/src/jenkins_hash.c new file mode 100644 index 0000000..1f0cd8b --- /dev/null +++ b/src/jenkins_hash.c @@ -0,0 +1,55 @@ +/* This file is part of Pazpar2. + Copyright (C) 2006-2009 Index Data + +Pazpar2 is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 2, or (at your option) any later +version. + +Pazpar2 is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +/** \file + \brief Jenkins hash function +*/ + +#if HAVE_CONFIG_H +#include +#endif + +#include "jenkins_hash.h" + +// Jenkins one-at-a-time hash (from wikipedia) +unsigned int jenkins_hash(const unsigned char *key) +{ + unsigned int hash = 0; + + while (*key) + { + hash += *(key++); + hash += (hash << 10); + hash ^= (hash >> 6); + } + hash += (hash << 3); + hash ^= (hash >> 11); + hash += (hash << 15); + return hash; +} + +/* + * Local variables: + * c-basic-offset: 4 + * c-file-style: "Stroustrup" + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ +