… | |
… | |
546 | typedef refptr<object> object_ptr; |
546 | typedef refptr<object> object_ptr; |
547 | typedef refptr<archetype> arch_ptr; |
547 | typedef refptr<archetype> arch_ptr; |
548 | typedef refptr<client> client_ptr; |
548 | typedef refptr<client> client_ptr; |
549 | typedef refptr<player> player_ptr; |
549 | typedef refptr<player> player_ptr; |
550 | |
550 | |
|
|
551 | #define STRHSH_NULL 2166136261 |
|
|
552 | |
|
|
553 | static inline uint32_t |
|
|
554 | strhsh (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 | |
|
|
569 | static inline uint32_t |
|
|
570 | memhsh (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 | |
551 | struct str_hash |
580 | struct 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 | |
589 | struct str_equal |
593 | struct str_equal |
590 | { |
594 | { |