ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/include/util.h
(Generate patch)

Comparing deliantra/server/include/util.h (file contents):
Revision 1.83 by root, Tue Dec 30 07:24:16 2008 UTC vs.
Revision 1.84 by root, Wed Dec 31 17:35:37 2008 UTC

41#endif 41#endif
42 42
43// put into ifs if you are very sure that the expression 43// put into ifs if you are very sure that the expression
44// is mostly true or mosty false. note that these return 44// is mostly true or mosty false. note that these return
45// booleans, not the expression. 45// booleans, not the expression.
46#define expect_false(expr) expect ((expr) != 0, 0) 46#define expect_false(expr) expect ((expr) ? 1 : 0, 0)
47#define expect_true(expr) expect ((expr) != 0, 1) 47#define expect_true(expr) expect ((expr) ? 1 : 0, 1)
48 48
49#include <pthread.h> 49#include <pthread.h>
50 50
51#include <cstddef> 51#include <cstddef>
52#include <cmath> 52#include <cmath>
540 540
541struct str_hash 541struct str_hash
542{ 542{
543 std::size_t operator ()(const char *s) const 543 std::size_t operator ()(const char *s) const
544 { 544 {
545 unsigned long hash = 0; 545#if 0
546 uint32_t hash = 0;
546 547
547 /* use the one-at-a-time hash function, which supposedly is 548 /* use the one-at-a-time hash function, which supposedly is
548 * better than the djb2-like one used by perl5.005, but 549 * better than the djb2-like one used by perl5.005, but
549 * certainly is better then the bug used here before. 550 * certainly is better then the bug used here before.
550 * see http://burtleburtle.net/bob/hash/doobs.html 551 * see http://burtleburtle.net/bob/hash/doobs.html
557 } 558 }
558 559
559 hash += hash << 3; 560 hash += hash << 3;
560 hash ^= hash >> 11; 561 hash ^= hash >> 11;
561 hash += hash << 15; 562 hash += hash << 15;
563#else
564 // use FNV-1a hash (http://isthe.com/chongo/tech/comp/fnv/)
565 // it is about twice as fast as the one-at-a-time one,
566 // with good distribution.
567 // FNV-1a is faster on many cpus because the multiplication
568 // runs concurrent with the looping logic.
569 uint32_t hash = 2166136261;
570
571 while (*s)
572 hash = (hash ^ *s++) * 16777619;
573#endif
562 574
563 return hash; 575 return hash;
564 } 576 }
565}; 577};
566 578

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines