mirror of
https://github.com/haproxy/haproxy.git
synced 2026-04-15 21:59:41 -04:00
62 lines
2.3 KiB
C
62 lines
2.3 KiB
C
/*
|
|
This File is copied from
|
|
|
|
http://www.oreilly.com/catalog/masteralgoc/index.html
|
|
Mastering Algorithms with C
|
|
By Kyle Loudon
|
|
ISBN: 1-56592-453-3
|
|
Publishd by O'Reilly
|
|
|
|
We have added our own struct to these function.
|
|
*/
|
|
|
|
/*****************************************************************************
|
|
* *
|
|
* ------------------------------- hashpjw.c ------------------------------ *
|
|
* *
|
|
*****************************************************************************/
|
|
|
|
#include <include/hashpjw.h>
|
|
|
|
/*****************************************************************************
|
|
* *
|
|
* -------------------------------- hashpjw ------------------------------- *
|
|
* *
|
|
*****************************************************************************/
|
|
|
|
int hashpjw(const void *key) {
|
|
|
|
const char *ptr;
|
|
unsigned int val;
|
|
appsess *appsession_temp;
|
|
|
|
/*****************************************************************************
|
|
* *
|
|
* Hash the key by performing a number of bit operations on it. *
|
|
* *
|
|
*****************************************************************************/
|
|
|
|
val = 0;
|
|
appsession_temp = (appsess *)key;
|
|
ptr = appsession_temp->sessid;
|
|
|
|
while (*ptr != '\0') {
|
|
|
|
int tmp;
|
|
|
|
val = (val << 4) + (*ptr);
|
|
|
|
if((tmp = (val & 0xf0000000))) {
|
|
val = val ^ (tmp >> 24);
|
|
val = val ^ tmp;
|
|
}
|
|
ptr++;
|
|
}/* end while */
|
|
|
|
/*****************************************************************************
|
|
* *
|
|
* In practice, replace PRIME_TBLSIZ with the actual table size. *
|
|
* *
|
|
*****************************************************************************/
|
|
return val % PRIME_TBLSIZ;
|
|
}/* end hashpjw */
|