Algorithm-Heapify-XS
view release on metacpan or search on metacpan
#ifndef UV_MAX
# define UV_MAX PERL_ULONG_MAX
#endif
#endif
#ifndef IVSIZE
# ifdef LONGSIZE
# define IVSIZE LONGSIZE
# else
# define IVSIZE 4 /* A bold guess, but the best we can make. */
# endif
#endif
#ifndef UVTYPE
# define UVTYPE unsigned IVTYPE
#endif
#ifndef UVSIZE
# define UVSIZE IVSIZE
#endif
#ifndef sv_setuv
#endif
#ifndef PERL_MAGIC_backref
# define PERL_MAGIC_backref '<'
#endif
#ifndef PERL_MAGIC_ext
# define PERL_MAGIC_ext '~'
#endif
/* That's the best we can do... */
#ifndef sv_catpvn_nomg
# define sv_catpvn_nomg sv_catpvn
#endif
#ifndef sv_catsv_nomg
# define sv_catsv_nomg sv_catsv
#endif
#ifndef sv_setsv_nomg
# define sv_setsv_nomg sv_setsv
t/max_heap.t view on Meta::CPAN
while (@{$arrays1[0]} and $taken{$arrays1[0][0][1]});
if (@{$arrays1[0]}) {
max_heap_adjust_top(@arrays1);
} else {
max_heap_shift(@arrays1);
}
}
last unless @arrays1;
my $best_ary= max_heap_shift(@arrays1);
my $best_item= $best_ary->[0];
my $job_id= $best_item->[1];
my $agent= $agent_array{0+$best_ary};
my $score= $best_item->[0];
$taken{$job_id}++;
push @sequence1, "$agent:$job_id";
}
}
$max_heap_elapsed += time();
my $max_heap_comparisons= OloadAry::reset_called_count();
my $sort_elapsed= 0 - time();
{
@$_= sort { $b <=> $a } @$_ for @arrays2;
@arrays2= sort { $b <=> $a } @arrays2;
#die Data::Dumper::Dumper(\@arrays2);
my %taken;
while (@arrays2) {
my $best_ary= shift @arrays2;
last if !@$best_ary;
my $best_item= shift @$best_ary;
my $agent= $agent_array{0+$best_ary};
my $score= $best_item->[0];
my $job_id= $best_item->[1];
push @sequence2, "$agent:$job_id";
$taken{$job_id}++;
foreach my $ary (@arrays2) {
shift @$ary while @$ary and $taken{$ary->[0][1]};
}
@arrays2= sort { $b <=> $a } grep { 0+@$_ } @arrays2;
}
}
$sort_elapsed += time();
my $sort_comparisons= OloadAry::reset_called_count();
t/min_heap.t view on Meta::CPAN
while (@{$arrays1[0]} and $taken{$arrays1[0][0][1]});
if (@{$arrays1[0]}) {
min_heap_adjust_top(@arrays1);
} else {
min_heap_shift(@arrays1);
}
}
last unless @arrays1;
my $best_ary= min_heap_shift(@arrays1);
my $best_item= $best_ary->[0];
my $job_id= $best_item->[1];
my $agent= $agent_array{0+$best_ary};
my $score= $best_item->[0];
$taken{$job_id}++;
push @sequence1, "$agent:$job_id";
}
}
$min_heap_elapsed += time();
my $min_heap_comparisons= OloadAry::reset_called_count();
my $sort_elapsed= 0 - time();
{
@$_= sort { $a <=> $b } @$_ for @arrays2;
@arrays2= sort { $a <=> $b } @arrays2;
#die Data::Dumper::Dumper(\@arrays2);
my %taken;
while (@arrays2) {
my $best_ary= shift @arrays2;
last if !@$best_ary;
my $best_item= shift @$best_ary;
my $agent= $agent_array{0+$best_ary};
my $score= $best_item->[0];
my $job_id= $best_item->[1];
push @sequence2, "$agent:$job_id";
$taken{$job_id}++;
foreach my $ary (@arrays2) {
shift @$ary while @$ary and $taken{$ary->[0][1]};
}
@arrays2= sort { $a <=> $b } grep { 0+@$_ } @arrays2;
}
}
$sort_elapsed += time();
my $sort_comparisons= OloadAry::reset_called_count();
( run in 0.438 second using v1.01-cache-2.11-cpan-4e96b696675 )