~ubuntu-branches/ubuntu/trusty/haproxy/trusty-backports

« back to all changes in this revision

Viewing changes to tests/test_hashes.c

  • Committer: Bazaar Package Importer
  • Author(s): Arnaud Cornet
  • Date: 2008-03-09 21:30:29 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080309213029-8oupnrc607mg5uqw
Tags: 1.3.14.3-1
* New Upstream Version
* Add status argument support to init-script to conform to LSB.
* Cleanup pidfile after stop in init script. Init script return code fixups.

Show diffs side-by-side

added added

removed removed

Lines of Context:
158
158
                       +(uint32_t)(((const uint8_t *)(d))[0]) )
159
159
#endif
160
160
 
161
 
/*
162
 
 * This function has a hole of 11 unused bits in bytes 2 and 3 of each block of
163
 
 * 32 bits.
164
 
 */
165
161
uint32_t SuperFastHash (const char * data, int len) {
166
162
uint32_t hash = len, tmp;
167
163
int rem;
208
204
}
209
205
 
210
206
/*
211
 
 * This variant uses all bits from the input block, and is about 15% faster.
 
207
 * This variant is about 15% faster.
212
208
 */
213
209
uint32_t SuperFastHash2 (const char * data, int len) {
214
210
uint32_t hash = len, tmp;
224
220
        register uint32_t next;
225
221
        next   = get16bits(data+2);
226
222
        hash  += get16bits(data);
227
 
        tmp    = ((next << 11) | (next >> 21)) ^ hash;
 
223
        tmp    = (next << 11) ^ hash;
228
224
        hash   = (hash << 16) ^ tmp;
229
225
        data  += 2*sizeof (uint16_t);
230
226
        hash  += hash >> 11;
493
489
  return h;
494
490
}
495
491
 
 
492
unsigned wt_hash ( void *key, int len )
 
493
{
 
494
  unsigned char *p = key;
 
495
  unsigned h = 0x783c965aUL;
 
496
  unsigned step = 16;
 
497
 
 
498
  for (; len > 0; len--) {
 
499
      h ^= *p * 9;
 
500
      p++;
 
501
      h = (h << step) | (h >> (32-step));
 
502
      step ^= h;
 
503
      step &= 0x1F;
 
504
  }
 
505
 
 
506
  return h;
 
507
}
 
508
 
496
509
 
497
510
#define run_test(fct, args) {                                           \
498
511
    unsigned long loop, count;                                          \
526
539
  start = urls;
527
540
  len = strlen(*urls);
528
541
 
 
542
  run_test(wt_hash, (*urls, len));
529
543
  run_test(SuperFastHash2, (*urls, len));
530
544
  run_test(SuperFastHash, (*urls, len));
531
545
  run_test(haproxy_uri_hash, (*urls, len));