Changeset 15683 for trunk/ippScripts/scripts/magic_tree.pl
- Timestamp:
- Nov 21, 2007, 5:11:47 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/ippScripts/scripts/magic_tree.pl (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippScripts/scripts/magic_tree.pl
r15681 r15683 189 189 contents => \@fields, # Contents of node 190 190 position => 'root', # Position in tree 191 children => {}, # Children of node 191 192 }; 192 193 my @tasks = ( $root ); … … 242 243 } 243 244 244 # Divide a node into upper and lower nodes 245 # Divide a list into two, returning the lower and upper parts 246 sub divide_list 247 { 248 my $list = shift; # List to divide 249 my $index = shift; # Name of index for sorting 250 251 my @sorted = sort { $$a{$index} <=> $$b{$index} } @$list; # Sorted list 252 my $median = int(scalar @sorted / 2); # Median point of list 253 my @upper = splice(@sorted, $median); # Upper part of the sorted list 254 255 return (\@sorted, \@upper); 256 } 257 258 # Create a new node, add it to the parent, and add it to the task list if required 259 sub new_node 260 { 261 my $parent = shift; # The parent node 262 my $contents = shift; # Contents of the new node 263 my $position = shift; # Position description 264 my $tasks = shift; # Tasks to do 265 266 my $node = { 267 contents => $contents, 268 position => $parent->{position} . '_' . $position, 269 children => {}, 270 }; 271 272 $parent->{children}->{$position} = $node; 273 274 push @$tasks, $node if scalar @$contents > 4; 275 276 return $node; 277 } 278 279 # Divide a node 245 280 sub divide_node 246 281 { … … 251 286 252 287 my $contents = $node->{contents} or die "Can't find contents of node."; # Contents of node 253 my $index = (not defined $node->{index} or $node->{index} eq 'xi') ? 'eta' : 'xi'; # Property to sort 254 my @sorted = sort { $$a{$index} <=> $$b{$index} } @$contents; # Sorted list 255 my $median = int(scalar @sorted / 2); # Median point of list 256 my @top = splice(@sorted, $median); # Top of the sorted list 257 258 my $upper = { # Upper node 259 contents => \@top, 260 index => $index, 261 position => $node->{position} . 'U', 262 }; 263 my $lower = { # Lower node 264 contents => \@sorted, 265 index => $index, 266 position => $node->{position} . 'L', 267 }; 268 269 $node->{upper} = $upper; 270 $node->{lower} = $lower; 288 289 my ($lower, $upper) = divide_list($contents, 'xi'); 290 291 if (scalar @$lower > 4) { 292 my ($ll, $lr) = divide_list($lower, 'eta'); 293 new_node($node, $ll, 'll', $tasks); 294 new_node($node, $lr, 'lr', $tasks); 295 } else { 296 new_node($node, $lower, 'L', $tasks); 297 } 298 299 if (scalar @$upper > 4) { 300 my ($ul, $ur) = divide_list($upper, 'eta'); 301 new_node($node, $ul, 'ul', $tasks); 302 new_node($node, $ur, 'ur', $tasks); 303 } else { 304 new_node($node, $upper, 'U', $tasks); 305 } 306 271 307 $node->{contents} = undef; 272 273 push @$tasks, $upper if scalar @top > MAX_FIELDS;274 push @$tasks, $lower if scalar @sorted > MAX_FIELDS;275 308 276 309 return $node; … … 293 326 } 294 327 } else { 295 $output .= "$position\t\tSTR\t${position}L\n";296 $output .= "$position\t\tSTR\t${position}U\n";297 $output .= print_node($node->{lower});298 $output .= print_node($node->{upper});328 foreach my $div ( keys %{$node->{children}} ) { 329 $output .= "$position\t\tSTR\t${position}_$div\n"; 330 $output .= print_node($node->{children}->{$div}); 331 } 299 332 } 300 333
Note:
See TracChangeset
for help on using the changeset viewer.
