willy tarreau | 1235015 | 2005-12-18 01:03:27 +0100 | [diff] [blame^] | 1 | /* |
| 2 | This File is copied from |
| 3 | |
| 4 | http://www.oreilly.com/catalog/masteralgoc/index.html |
| 5 | Mastering Algorithms with C |
| 6 | By Kyle Loudon |
| 7 | ISBN: 1-56592-453-3 |
| 8 | Publishd by O'Reilly |
| 9 | |
| 10 | We have added our own struct to these function. |
| 11 | */ |
| 12 | |
| 13 | /***************************************************************************** |
| 14 | * * |
| 15 | * ------------------------------- hashpjw.c ------------------------------ * |
| 16 | * * |
| 17 | *****************************************************************************/ |
| 18 | |
| 19 | #include <include/hashpjw.h> |
| 20 | |
| 21 | /***************************************************************************** |
| 22 | * * |
| 23 | * -------------------------------- hashpjw ------------------------------- * |
| 24 | * * |
| 25 | *****************************************************************************/ |
| 26 | |
| 27 | int hashpjw(const void *key) { |
| 28 | |
| 29 | const char *ptr; |
| 30 | unsigned int val; |
| 31 | AppSess *appsession_temp; |
| 32 | |
| 33 | /***************************************************************************** |
| 34 | * * |
| 35 | * Hash the key by performing a number of bit operations on it. * |
| 36 | * * |
| 37 | *****************************************************************************/ |
| 38 | |
| 39 | val = 0; |
| 40 | appsession_temp = (AppSess *)key; |
| 41 | ptr = appsession_temp->sessid; |
| 42 | |
| 43 | while (*ptr != '\0') { |
| 44 | |
| 45 | int tmp; |
| 46 | |
| 47 | val = (val << 4) + (*ptr); |
| 48 | |
| 49 | if((tmp = (val & 0xf0000000))) { |
| 50 | val = val ^ (tmp >> 24); |
| 51 | val = val ^ tmp; |
| 52 | } |
| 53 | ptr++; |
| 54 | }/* end while */ |
| 55 | |
| 56 | /***************************************************************************** |
| 57 | * * |
| 58 | * In practice, replace PRIME_TBLSIZ with the actual table size. * |
| 59 | * * |
| 60 | *****************************************************************************/ |
| 61 | return val % PRIME_TBLSIZ; |
| 62 | }/* end hashpjw */ |