00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef _HASH_FUNC_H_
00039 #define _HASH_FUNC_H_
00040
00041 #include "str.h"
00042
00043
00044 #define ch_h_inc h+=v^(v>>3)
00045 #define ch_icase(_c) (((_c)>='A'&&(_c)<='Z')?((_c)|0x20):(_c))
00046 static inline unsigned int core_hash(const str *s1, const str *s2, const unsigned int size)
00047 {
00048 char *p, *end;
00049 register unsigned v;
00050 register unsigned h;
00051
00052 h=0;
00053
00054 end=s1->s+s1->len;
00055 for ( p=s1->s ; p<=(end-4) ; p+=4 ){
00056 v=(*p<<24)+(p[1]<<16)+(p[2]<<8)+p[3];
00057 ch_h_inc;
00058 }
00059 v=0;
00060 for (; p<end ; p++){ v<<=8; v+=*p;}
00061 ch_h_inc;
00062
00063 if (s2) {
00064 end=s2->s+s2->len;
00065 for (p=s2->s; p<=(end-4); p+=4){
00066 v=(*p<<24)+(p[1]<<16)+(p[2]<<8)+p[3];
00067 ch_h_inc;
00068 }
00069 v=0;
00070 for (; p<end ; p++){ v<<=8; v+=*p;}
00071 ch_h_inc;
00072 }
00073 h=((h)+(h>>11))+((h>>13)+(h>>23));
00074 return size?((h)&(size-1)):h;
00075 }
00076
00077
00078 static inline unsigned int core_case_hash( str *s1, str *s2, unsigned int size)
00079 {
00080 char *p, *end;
00081 register unsigned v;
00082 register unsigned h;
00083
00084 h=0;
00085
00086 end=s1->s+s1->len;
00087 for ( p=s1->s ; p<=(end-4) ; p+=4 ){
00088 v=(ch_icase(*p)<<24)+(ch_icase(p[1])<<16)+(ch_icase(p[2])<<8)
00089 + ch_icase(p[3]);
00090 ch_h_inc;
00091 }
00092 v=0;
00093 for (; p<end ; p++){ v<<=8; v+=ch_icase(*p);}
00094 ch_h_inc;
00095
00096 if (s2) {
00097 end=s2->s+s2->len;
00098 for (p=s2->s; p<=(end-4); p+=4){
00099 v=(ch_icase(*p)<<24)+(ch_icase(p[1])<<16)+(ch_icase(p[2])<<8)
00100 + ch_icase(p[3]);
00101 ch_h_inc;
00102 }
00103 v=0;
00104 for (; p<end ; p++){ v<<=8; v+=ch_icase(*p);}
00105 ch_h_inc;
00106 }
00107 h=((h)+(h>>11))+((h>>13)+(h>>23));
00108 return size?((h)&(size-1)):h;
00109 }
00110
00111
00112 #endif