1 | /* |
1 | /* |
2 | * static char *rcsid_arch_c = |
2 | * static char *rcsid_arch_c = |
3 | * "$Id: arch.c,v 1.1.1.2 2006/02/22 18:01:17 elmex Exp $"; |
3 | * "$Id: arch.c,v 1.3 2006/08/13 17:16:00 elmex dead $"; |
4 | */ |
4 | */ |
5 | |
5 | |
6 | /* |
6 | /* |
7 | CrossFire, A Multiplayer game for X-windows |
7 | CrossFire, A Multiplayer game for X-windows |
8 | |
8 | |
… | |
… | |
634 | |
634 | |
635 | unsigned long |
635 | unsigned long |
636 | hasharch(const char *str, int tablesize) { |
636 | hasharch(const char *str, int tablesize) { |
637 | unsigned long hash = 0; |
637 | unsigned long hash = 0; |
638 | int i = 0; |
638 | int i = 0; |
639 | unsigned rot = 0; |
|
|
640 | const char *p; |
639 | const unsigned char *p; |
641 | |
640 | |
|
|
641 | /* use the one-at-a-time hash function, which supposedly is |
|
|
642 | * better than the djb2-like one used by perl5.005, but |
|
|
643 | * certainly is better then the bug used here before. |
|
|
644 | * see http://burtleburtle.net/bob/hash/doobs.html |
|
|
645 | */ |
642 | for (p = str; i < MAXSTRING && *p; p++, i++) { |
646 | for (p = str; i < MAXSTRING && *p; p++, i++) { |
643 | hash ^= (unsigned long) *p << rot; |
647 | hash += *p; |
644 | rot += 2; |
648 | hash += hash << 10; |
645 | if (rot >= (sizeof(long) - sizeof(char)) * 8) |
649 | hash ^= hash >> 6; |
646 | rot = 0; |
|
|
647 | } |
650 | } |
|
|
651 | hash += hash << 3; |
|
|
652 | hash ^= hash >> 11; |
|
|
653 | hash += hash << 15; |
648 | return (hash % tablesize); |
654 | return hash % tablesize; |
649 | } |
655 | } |
650 | |
656 | |
651 | /* |
657 | /* |
652 | * Finds, using the hashtable, which archetype matches the given name. |
658 | * Finds, using the hashtable, which archetype matches the given name. |
653 | * returns a pointer to the found archetype, otherwise NULL. |
659 | * returns a pointer to the found archetype, otherwise NULL. |