Sha256: 6cb5c0cf7ffa2c65f4f9945ed73ac2b6323dbd21e3676648242422f53746bc32
Contents?: true
Size: 1.83 KB
Versions: 3
Compression:
Stored size: 1.83 KB
Contents
#include <stdio.h> unsigned long elf_hash(const unsigned char *name) { unsigned long h = 0, g; while (*name) { h = (h << 4) + *name++; if (g = h & 0xf0000000) h ^= g >> 24; h &= ~g; } return h; } static unsigned int _dl_elf_hash (const char *name_arg) { const unsigned char *name = (const unsigned char *) name_arg; unsigned long int hash = *name; if (hash != 0 && name[1] != '\0') { hash = (hash << 4) + name[1]; if (name[2] != '\0') { hash = (hash << 4) + name[2]; if (name[3] != '\0') { hash = (hash << 4) + name[3]; if (name[4] != '\0') { hash = (hash << 4) + name[4]; name += 5; while (*name != '\0') { unsigned long int hi; hash = (hash << 4) + *name++; hi = hash & 0xf0000000; /* The algorithm specified in the ELF ABI is as follows: if (hi != 0) hash ^= hi >> 24; hash &= ~hi; But the following is equivalent and a lot faster, especially on modern processors. */ hash ^= hi >> 24; } /* Second part of the modified formula. This operation can be lifted outside the loop. */ hash &= 0x0fffffff; } } } } return hash; } int main(){ while(!feof(stdin)){ char buf[1024]; scanf("%1024s",buf); unsigned long ehash1 = elf_hash(buf); unsigned long ehash2 = _dl_elf_hash(buf); printf("%lu\t %lu \n",ehash1,ehash2); } }
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
elf-mithril-0.0.5 | tools/hash_test.c |
elf-mithril-0.0.4 | tools/hash_test.c |
elf-mithril-0.0.1 | tools/hash_test.c |