sub heapSort{
my %hashMap=@_;
my $heap = Heap::Fibonacci::Fast->new();
my $num = 0;
foreach my $kk (keys %hashMap) {
my $k = $hashMap{$kk};
my $v = $kk;
if( $num < 1000 ){
$heap->key_insert($k, $v);
$num ++;
}else{
my $top_key = $heap->top_key();
if( $k > $top_key){
$heap->extract_top();
$heap->key_insert($k, $v);
}
}
}
my $k_top;
my $v_top;
my @rstRank=();
while( defined( $k_top = $heap->top_key())) {
$v_top = $heap->extract_top();
my $count = $k_top;
my $name = $v_top;
my $v = {"name"=>$name,"count"=>$count};
push(@rstRank,$v);
}
@rstRank;
}
perl heapSort
最新推荐文章于 2019-01-13 06:58:14 发布