14
14
the public domain. It has no warranty.
16
16
You probably want to use hashlittle(). hashlittle() and hashbig()
17
hash byte arrays. hashlittle() is is faster than hashbig() on
17
hash byte arrays. hashlittle() is faster than hashbig() on
18
18
little-endian machines. Intel and AMD are little-endian machines.
19
19
On second thought, you probably want hashlittle2(), which is identical to
20
20
hashlittle() except it returns two 32-bit hashes for the price of one.
315
315
* rest of the string. Every machine with memory protection I've seen
316
316
* does it on word boundaries, so is OK with this. But VALGRIND will
317
317
* still catch it and complain. The masking trick does make the hash
318
* noticably faster for short strings (like English words).
318
* noticeably faster for short strings (like English words).
339
339
#else /* make valgrind happy */
341
k8 = (const uint8_t *)k;
344
case 12: c+=k[2]; b+=k[1]; a+=k[0]; break;
345
case 11: c+=((uint32_t)k8[10])<<16; /* fall through */
346
case 10: c+=((uint32_t)k8[9])<<8; /* fall through */
347
case 9 : c+=k8[8]; /* fall through */
348
case 8 : b+=k[1]; a+=k[0]; break;
349
case 7 : b+=((uint32_t)k8[6])<<16; /* fall through */
350
case 6 : b+=((uint32_t)k8[5])<<8; /* fall through */
351
case 5 : b+=k8[4]; /* fall through */
352
case 4 : a+=k[0]; break;
353
case 3 : a+=((uint32_t)k8[2])<<16; /* fall through */
354
case 2 : a+=((uint32_t)k8[1])<<8; /* fall through */
355
case 1 : a+=k8[0]; break;
341
const uint8_t *k8 = (const uint8_t *) k;
345
case 12: c+=k[2]; b+=k[1]; a+=k[0]; break;
346
case 11: c+=((uint32_t)k8[10])<<16; /* fall through */
347
case 10: c+=((uint32_t)k8[9])<<8; /* fall through */
348
case 9 : c+=k8[8]; /* fall through */
349
case 8 : b+=k[1]; a+=k[0]; break;
350
case 7 : b+=((uint32_t)k8[6])<<16; /* fall through */
351
case 6 : b+=((uint32_t)k8[5])<<8; /* fall through */
352
case 5 : b+=k8[4]; /* fall through */
353
case 4 : a+=k[0]; break;
354
case 3 : a+=((uint32_t)k8[2])<<16; /* fall through */
355
case 2 : a+=((uint32_t)k8[1])<<8; /* fall through */
356
case 1 : a+=k8[0]; break;
359
361
#endif /* !valgrind */
499
501
* rest of the string. Every machine with memory protection I've seen
500
502
* does it on word boundaries, so is OK with this. But VALGRIND will
501
503
* still catch it and complain. The masking trick does make the hash
502
* noticably faster for short strings (like English words).
504
* noticeably faster for short strings (like English words).
523
525
#else /* make valgrind happy */
525
k8 = (const uint8_t *)k;
528
case 12: c+=k[2]; b+=k[1]; a+=k[0]; break;
529
case 11: c+=((uint32_t)k8[10])<<16; /* fall through */
530
case 10: c+=((uint32_t)k8[9])<<8; /* fall through */
531
case 9 : c+=k8[8]; /* fall through */
532
case 8 : b+=k[1]; a+=k[0]; break;
533
case 7 : b+=((uint32_t)k8[6])<<16; /* fall through */
534
case 6 : b+=((uint32_t)k8[5])<<8; /* fall through */
535
case 5 : b+=k8[4]; /* fall through */
536
case 4 : a+=k[0]; break;
537
case 3 : a+=((uint32_t)k8[2])<<16; /* fall through */
538
case 2 : a+=((uint32_t)k8[1])<<8; /* fall through */
539
case 1 : a+=k8[0]; break;
540
case 0 : *pc=c; *pb=b; return; /* zero length strings require no mixing */
528
const uint8_t *k8 = (const uint8_t *)k;
531
case 12: c+=k[2]; b+=k[1]; a+=k[0]; break;
532
case 11: c+=((uint32_t)k8[10])<<16; /* fall through */
533
case 10: c+=((uint32_t)k8[9])<<8; /* fall through */
534
case 9 : c+=k8[8]; /* fall through */
535
case 8 : b+=k[1]; a+=k[0]; break;
536
case 7 : b+=((uint32_t)k8[6])<<16; /* fall through */
537
case 6 : b+=((uint32_t)k8[5])<<8; /* fall through */
538
case 5 : b+=k8[4]; /* fall through */
539
case 4 : a+=k[0]; break;
540
case 3 : a+=((uint32_t)k8[2])<<16; /* fall through */
541
case 2 : a+=((uint32_t)k8[1])<<8; /* fall through */
542
case 1 : a+=k8[0]; break;
543
case 0 : *pc=c; *pb=b; return; /* zero length strings require no mixing */
543
547
#endif /* !valgrind */
675
679
* rest of the string. Every machine with memory protection I've seen
676
680
* does it on word boundaries, so is OK with this. But VALGRIND will
677
681
* still catch it and complain. The masking trick does make the hash
678
* noticably faster for short strings (like English words).
682
* noticeably faster for short strings (like English words).
699
703
#else /* make valgrind happy */
701
k8 = (const uint8_t *)k;
702
switch(length) /* all the case statements fall through */
704
case 12: c+=k[2]; b+=k[1]; a+=k[0]; break;
705
case 11: c+=((uint32_t)k8[10])<<8; /* fall through */
706
case 10: c+=((uint32_t)k8[9])<<16; /* fall through */
707
case 9 : c+=((uint32_t)k8[8])<<24; /* fall through */
708
case 8 : b+=k[1]; a+=k[0]; break;
709
case 7 : b+=((uint32_t)k8[6])<<8; /* fall through */
710
case 6 : b+=((uint32_t)k8[5])<<16; /* fall through */
711
case 5 : b+=((uint32_t)k8[4])<<24; /* fall through */
712
case 4 : a+=k[0]; break;
713
case 3 : a+=((uint32_t)k8[2])<<8; /* fall through */
714
case 2 : a+=((uint32_t)k8[1])<<16; /* fall through */
715
case 1 : a+=((uint32_t)k8[0])<<24; break;
706
const uint8_t *k8 = (const uint8_t *)k;
707
switch(length) /* all the case statements fall through */
709
case 12: c+=k[2]; b+=k[1]; a+=k[0]; break;
710
case 11: c+=((uint32_t)k8[10])<<8; /* fall through */
711
case 10: c+=((uint32_t)k8[9])<<16; /* fall through */
712
case 9 : c+=((uint32_t)k8[8])<<24; /* fall through */
713
case 8 : b+=k[1]; a+=k[0]; break;
714
case 7 : b+=((uint32_t)k8[6])<<8; /* fall through */
715
case 6 : b+=((uint32_t)k8[5])<<16; /* fall through */
716
case 5 : b+=((uint32_t)k8[4])<<24; /* fall through */
717
case 4 : a+=k[0]; break;
718
case 3 : a+=((uint32_t)k8[2])<<8; /* fall through */
719
case 2 : a+=((uint32_t)k8[1])<<16; /* fall through */
720
case 1 : a+=((uint32_t)k8[0])<<24; break;
719
725
#endif /* !VALGRIND */