Mercurial > hg > CbC > CbC_gcc
comparison libiberty/hashtab.c @ 111:04ced10e8804
gcc 7
author | kono |
---|---|
date | Fri, 27 Oct 2017 22:46:09 +0900 |
parents | f6334be47118 |
children | 84e7813d76e9 |
comparison
equal
deleted
inserted
replaced
68:561a7518be6b | 111:04ced10e8804 |
---|---|
1 /* An expandable hash tables datatype. | 1 /* An expandable hash tables datatype. |
2 Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2009, 2010 | 2 Copyright (C) 1999-2017 Free Software Foundation, Inc. |
3 Free Software Foundation, Inc. | |
4 Contributed by Vladimir Makarov (vmakarov@cygnus.com). | 3 Contributed by Vladimir Makarov (vmakarov@cygnus.com). |
5 | 4 |
6 This file is part of the libiberty library. | 5 This file is part of the libiberty library. |
7 Libiberty is free software; you can redistribute it and/or | 6 Libiberty is free software; you can redistribute it and/or |
8 modify it under the terms of the GNU Library General Public | 7 modify it under the terms of the GNU Library General Public |
190 fprintf (stderr, "Cannot find prime bigger than %lu\n", n); | 189 fprintf (stderr, "Cannot find prime bigger than %lu\n", n); |
191 abort (); | 190 abort (); |
192 } | 191 } |
193 | 192 |
194 return low; | 193 return low; |
195 } | |
196 | |
197 /* Returns a hash code for P. */ | |
198 | |
199 static hashval_t | |
200 hash_pointer (const PTR p) | |
201 { | |
202 return (hashval_t) ((intptr_t)p >> 3); | |
203 } | 194 } |
204 | 195 |
205 /* Returns non-zero if P1 and P2 are equal. */ | 196 /* Returns non-zero if P1 and P2 are equal. */ |
206 | 197 |
207 static int | 198 static int |
968 | 959 |
969 /*------------------------------------- handle the last 11 bytes */ | 960 /*------------------------------------- handle the last 11 bytes */ |
970 c += length; | 961 c += length; |
971 switch(len) /* all the case statements fall through */ | 962 switch(len) /* all the case statements fall through */ |
972 { | 963 { |
973 case 11: c+=((hashval_t)k[10]<<24); | 964 case 11: c+=((hashval_t)k[10]<<24); /* fall through */ |
974 case 10: c+=((hashval_t)k[9]<<16); | 965 case 10: c+=((hashval_t)k[9]<<16); /* fall through */ |
975 case 9 : c+=((hashval_t)k[8]<<8); | 966 case 9 : c+=((hashval_t)k[8]<<8); /* fall through */ |
976 /* the first byte of c is reserved for the length */ | 967 /* the first byte of c is reserved for the length */ |
977 case 8 : b+=((hashval_t)k[7]<<24); | 968 case 8 : b+=((hashval_t)k[7]<<24); /* fall through */ |
978 case 7 : b+=((hashval_t)k[6]<<16); | 969 case 7 : b+=((hashval_t)k[6]<<16); /* fall through */ |
979 case 6 : b+=((hashval_t)k[5]<<8); | 970 case 6 : b+=((hashval_t)k[5]<<8); /* fall through */ |
980 case 5 : b+=k[4]; | 971 case 5 : b+=k[4]; /* fall through */ |
981 case 4 : a+=((hashval_t)k[3]<<24); | 972 case 4 : a+=((hashval_t)k[3]<<24); /* fall through */ |
982 case 3 : a+=((hashval_t)k[2]<<16); | 973 case 3 : a+=((hashval_t)k[2]<<16); /* fall through */ |
983 case 2 : a+=((hashval_t)k[1]<<8); | 974 case 2 : a+=((hashval_t)k[1]<<8); /* fall through */ |
984 case 1 : a+=k[0]; | 975 case 1 : a+=k[0]; |
985 /* case 0: nothing left to add */ | 976 /* case 0: nothing left to add */ |
986 } | 977 } |
987 mix(a,b,c); | 978 mix(a,b,c); |
988 /*-------------------------------------------- report the result */ | 979 /*-------------------------------------------- report the result */ |
989 return c; | 980 return c; |
990 } | 981 } |
982 | |
983 /* Returns a hash code for pointer P. Simplified version of evahash */ | |
984 | |
985 static hashval_t | |
986 hash_pointer (const PTR p) | |
987 { | |
988 intptr_t v = (intptr_t) p; | |
989 unsigned a, b, c; | |
990 | |
991 a = b = 0x9e3779b9; | |
992 a += v >> (sizeof (intptr_t) * CHAR_BIT / 2); | |
993 b += v & (((intptr_t) 1 << (sizeof (intptr_t) * CHAR_BIT / 2)) - 1); | |
994 c = 0x42135234; | |
995 mix (a, b, c); | |
996 return c; | |
997 } |