Changeset 39056 in webkit for trunk/JavaScriptCore/create_hash_table
- Timestamp:
- Dec 5, 2008, 5:05:06 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/create_hash_table
r38155 r39056 47 47 my $inside = 0; 48 48 my $name; 49 my $size; 49 my $pefectHashSize; 50 my $compactSize; 51 my $compactHashSizeMask; 50 52 my $banner = 0; 51 sub calcSize(); 53 sub calcPerfectHashSize(); 54 sub calcCompactHashSize(); 52 55 sub output(); 53 56 sub jsc_ucfirst($); … … 66 69 } 67 70 } elsif (/^\@end\s*$/ && $inside) { 68 calcSize(); 71 calcPerfectHashSize(); 72 calcCompactHashSize(); 69 73 output(); 70 74 … … 117 121 sub ceilingToPowerOf2 118 122 { 119 my ($ size) = @_;123 my ($pefectHashSize) = @_; 120 124 121 125 my $powerOf2 = 1; 122 while ($ size > $powerOf2) {126 while ($pefectHashSize > $powerOf2) { 123 127 $powerOf2 <<= 1; 124 128 } … … 127 131 } 128 132 129 sub calc Size()133 sub calcPerfectHashSize() 130 134 { 131 135 tableSizeLoop: 132 for ($ size = ceilingToPowerOf2(scalar @keys); ; $size += $size) {136 for ($pefectHashSize = ceilingToPowerOf2(scalar @keys); ; $pefectHashSize += $pefectHashSize) { 133 137 my @table = (); 134 138 foreach my $key (@keys) { 135 my $h = hashValue($key) % $ size;139 my $h = hashValue($key) % $pefectHashSize; 136 140 next tableSizeLoop if $table[$h]; 137 141 $table[$h] = 1; … … 144 148 my ($value, $distance) = @_; 145 149 return (($value << $distance) & 0xFFFFFFFF); 150 } 151 152 sub calcCompactHashSize() 153 { 154 my @table = (); 155 my @links = (); 156 my $compactHashSize = ceilingToPowerOf2(2 * @keys); 157 $compactHashSizeMask = $compactHashSize - 1; 158 $compactSize = $compactHashSize; 159 my $collisions = 0; 160 my $maxdepth = 0; 161 my $i = 0; 162 foreach my $key (@keys) { 163 my $depth = 0; 164 my $h = hashValue($key) % $compactHashSize; 165 while (defined($table[$h])) { 166 if (defined($links[$h])) { 167 $h = $links[$h]; 168 $depth++; 169 } else { 170 $collisions++; 171 $links[$h] = $compactSize; 172 $h = $compactSize; 173 $compactSize++; 174 } 175 } 176 $table[$h] = $i; 177 $i++; 178 $maxdepth = $depth if ( $depth > $maxdepth); 179 } 146 180 } 147 181 … … 237 271 print " { 0, 0, 0, 0 }\n"; 238 272 print "};\n\n"; 239 print "extern const struct HashTable $name = "; 240 print "\{ ", $size - 1, ", $nameEntries, 0 \};\n\n"; 273 print "extern const struct HashTable $name =\n"; 274 print "#if ENABLE(PERFECT_HASH_SIZE)\n"; 275 print " \{ ", $pefectHashSize - 1, ", $nameEntries, 0 \};\n"; 276 print "#else\n"; 277 print " \{ $compactSize, $compactHashSizeMask, $nameEntries, 0 \};\n"; 278 print "#endif\n\n"; 241 279 print "} // namespace\n"; 242 280 }
Note:
See TracChangeset
for help on using the changeset viewer.