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.94 by root, Sun Nov 8 16:13:45 2009 UTC vs.
Revision 1.95 by root, Tue Nov 10 00:01:31 2009 UTC

546typedef refptr<object> object_ptr; 546typedef refptr<object> object_ptr;
547typedef refptr<archetype> arch_ptr; 547typedef refptr<archetype> arch_ptr;
548typedef refptr<client> client_ptr; 548typedef refptr<client> client_ptr;
549typedef refptr<player> player_ptr; 549typedef refptr<player> player_ptr;
550 550
551#define STRHSH_NULL 2166136261
552
553static inline uint32_t
554strhsh (const char *s)
555{
556 // use FNV-1a hash (http://isthe.com/chongo/tech/comp/fnv/)
557 // it is about twice as fast as the one-at-a-time one,
558 // with good distribution.
559 // FNV-1a is faster on many cpus because the multiplication
560 // runs concurrently with the looping logic.
561 uint32_t hash = STRHSH_NULL;
562
563 while (*s)
564 hash = (hash ^ *s++) * 16777619;
565
566 return hash;
567}
568
569static inline uint32_t
570memhsh (const char *s, size_t len)
571{
572 uint32_t hash = STRHSH_NULL;
573
574 while (len--)
575 hash = (hash ^ *s++) * 16777619;
576
577 return hash;
578}
579
551struct str_hash 580struct str_hash
552{ 581{
553 std::size_t operator ()(const char *s) const 582 std::size_t operator ()(const char *s) const
554 { 583 {
555#if 0
556 uint32_t hash = 0;
557
558 /* use the one-at-a-time hash function, which supposedly is
559 * better than the djb2-like one used by perl5.005, but
560 * certainly is better then the bug used here before.
561 * see http://burtleburtle.net/bob/hash/doobs.html
562 */
563 while (*s)
564 {
565 hash += *s++;
566 hash += hash << 10;
567 hash ^= hash >> 6;
568 }
569
570 hash += hash << 3;
571 hash ^= hash >> 11;
572 hash += hash << 15;
573#else
574 // use FNV-1a hash (http://isthe.com/chongo/tech/comp/fnv/)
575 // it is about twice as fast as the one-at-a-time one,
576 // with good distribution.
577 // FNV-1a is faster on many cpus because the multiplication
578 // runs concurrent with the looping logic.
579 uint32_t hash = 2166136261;
580
581 while (*s)
582 hash = (hash ^ *s++) * 16777619;
583#endif
584
585 return hash; 584 return strhsh (s);
585 }
586
587 std::size_t operator ()(const shstr &s) const
588 {
589 return strhsh (s);
586 } 590 }
587}; 591};
588 592
589struct str_equal 593struct str_equal
590{ 594{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines