1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
/*
* $Id: hash_func.h,v 1.5 2006/03/13 12:29:46 bogdan_iancu Exp $
*
* Copyright (C) 2001-2003 FhG Fokus
*
* This file is part of openser, a free SIP server.
*
* openser 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 of the License, or
* (at your option) any later version
*
* openser 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* History:
*---------
*
* 2006-01-20 - new_hash1() added; support for configurable hash size
* added (bogdan)
* 2006-03-13 - new_hash1() and new_hash2() merged into core_hash();
* added core_case_hash() for case insensitive hashes;
* all TM dependet stuff moved to TM config file (bogdan)
*/
#ifndef _HASH_FUNC_H_
#define _HASH_FUNC_H_
#include "str.h"
#define ch_h_inc h+=v^(v>>3)
#define ch_icase(_c) (((_c)>='A'&&(_c)<='Z')?((_c)|0x20):(_c))
static inline unsigned int core_hash( str *s1, str *s2, unsigned int size )
{
char *p, *end;
register unsigned v;
register unsigned h;
h=0;
end=s1->s+s1->len;
for ( p=s1->s ; p<=(end-4) ; p+=4 ){
v=(*p<<24)+(p[1]<<16)+(p[2]<<8)+p[3];
ch_h_inc;
}
v=0;
for (; p<end ; p++){ v<<=8; v+=*p;}
ch_h_inc;
if (s2) {
end=s2->s+s2->len;
for (p=s2->s; p<=(end-4); p+=4){
v=(*p<<24)+(p[1]<<16)+(p[2]<<8)+p[3];
ch_h_inc;
}
v=0;
for (; p<end ; p++){ v<<=8; v+=*p;}
ch_h_inc;
}
h=((h)+(h>>11))+((h>>13)+(h>>23));
return size?((h)&(size-1)):h;
}
static inline unsigned int core_case_hash( str *s1, str *s2, unsigned int size)
{
char *p, *end;
register unsigned v;
register unsigned h;
h=0;
end=s1->s+s1->len;
for ( p=s1->s ; p<=(end-4) ; p+=4 ){
v=(ch_icase(*p)<<24)+(p[1]<<16)+(p[2]<<8)+p[3];
ch_h_inc;
}
v=0;
for (; p<end ; p++){ v<<=8; v+=ch_icase(*p);}
ch_h_inc;
if (s2) {
end=s2->s+s2->len;
for (p=s2->s; p<=(end-4); p+=4){
v=(ch_icase(*p)<<24)+(p[1]<<16)+(p[2]<<8)+p[3];
ch_h_inc;
}
v=0;
for (; p<end ; p++){ v<<=8; v+=ch_icase(*p);}
ch_h_inc;
}
h=((h)+(h>>11))+((h>>13)+(h>>23));
return size?((h)&(size-1)):h;
}
#endif
|