Skip to content

Instantly share code, notes, and snippets.

@c9s
Created May 25, 2014 12:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save c9s/bf4c665f18b4fd33f310 to your computer and use it in GitHub Desktop.
Save c9s/bf4c665f18b4fd33f310 to your computer and use it in GitHub Desktop.
1 106
1 146
1 152
1 159
1 184
1 201
1 21
1 216
1 245
1 254
1 273
1 274
1 278
1 28
1 288
1 294
1 308
1 323
1 327
1 341
1 344
1 345
1 417
1 438
1 45
1 453
1 455
1 458
1 459
1 467
1 479
1 489
1 64
1 66
2 8
1 95
1 96
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
unsigned long hash(unsigned char *str)
{
// unsigned long hash = 5381;
unsigned long hash = 0;
int c;
while (c = *str++) {
hash = hash + (hash << 5) + c; /* hash * 33 + c */
}
return hash % 500;
}
uint64_t slash_hash(const char *s)
{
union { uint64_t h; uint8_t u[8]; } hash;
int i=0;
hash.h = strlen(s);
while (*s) {
hash.u[i%8] += *s + i + (*s >> ((hash.h/(i+1)) % 5));
s++;
i++;
}
return hash.h; // 64-bit
}
int main()
{
FILE *fp = fopen("request-header.list","r");
char buf[128];
char * ret;
char * c;
while(ret = fgets(buf, 128, fp)) {
*(buf + strlen(buf) - 1) = '\0';
printf("%24s: %d\n",buf, hash(buf));
}
fclose(fp);
return 0;
}
Cache-Control
Connection
Date
Pragma
Trailer
Transfer-Encoding
Upgrade
Via
Warning
Accept
Accept-Charset
Accept-Encoding
Accept-Language
Authorization
Expect
From
Host
If-Match
If-Modified-Since
If-None-Match
If-Range
If-Unmodified-Since
Max-Forwards
Proxy-Authorization
Range
Referer
TE
User-Agent
Allow
Content-Encoding
Content-Language
Content-Length
Content-Location
Content-MD5
Content-Range
Content-Type
Expires
Last-Modified
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment