File: genhash.pl

package info (click to toggle)
syslinux 2%3A3.71%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 18,336 kB
  • ctags: 49,435
  • sloc: ansic: 188,623; asm: 12,943; pascal: 7,861; perl: 3,446; makefile: 1,968; sh: 771; python: 470; java: 324; xml: 14; php: 4
file content (26 lines) | stat: -rwxr-xr-x 606 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/perl
#
# Generate hash values for keywords
#

eval { use bytes; };

while ( defined($keywd = <STDIN>) ) {
    chomp $keywd;

    ($keywd,$keywdname) = split(/\s+/, $keywd);
    $keywdname = $keywd unless ( $keywdname );

    $l = length($keywd);
    $h = 0;
    for ( $i = 0 ; $i < $l ; $i++ ) {
	$c = ord(substr($keywd,$i,1)) | 0x20;
	$h = ((($h << 5)|($h >> 27)) ^ $c) & 0xFFFFFFFF;
    }
    if ( $seenhash{$h} ) {
	printf STDERR "$0: hash collision (0x%08x) %s %s\n",
	$h, $keywd, $seenhash{$h};
    }
    $seenhash{$h} = $keywd;
    printf("%-23s equ 0x%08x\n", "hash_${keywdname}", $h);
}