in reply to Re: In-place sort with order assignment
in thread In-place sort with order assignment
I tried that, and I think it might work, but it takes an extraordinary amount of time. So much so that I never actually saw it complete. To counter that, I tried extracting and deleting the keys in batches of 1000:
my @ordered; while( my $n = keys %hash ) { my @temp; for ( 1 .. $n < 1000 ? $n : 1000 ) { push @temp, scalar each %hash; } delete @hash{ @temp }; push @ordered, @temp; }
But it still takes an extraordinary amount of time.
Update: The above has a precedence problem with the ternary expression! And results in for loop operating from 1 to 1.
Add a set of parens and things go much more quickly:
my @ordered; while( my $n = keys %hash ) { my @temp; for ( 1 .. ( $n < 1000 ? $n : 1000 ) ) { push @temp, scalar each %hash; } delete @hash{ @temp }; push @ordered, @temp; }
BTW: If I ever manage to get the keys out of the hash and into an array without blowing memory, then I intend to use your Sort::Key to sort them in-place. But, there doesn't seem to be a an in-place version of keysort that doesn't take a callback?
I can use keysort_inplace{ $_ } @ordered;, but doesn't the callback slow things down?
I can use rsort_inplace @array and just assign the numbers reversed, but it seems there should be a sort_inplace() version?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: In-place sort with order assignment
by salva (Canon) on Sep 19, 2010 at 16:41 UTC | |
by BrowserUk (Patriarch) on Sep 19, 2010 at 19:37 UTC | |
by salva (Canon) on Sep 20, 2010 at 07:23 UTC | |
by BrowserUk (Patriarch) on Sep 20, 2010 at 07:47 UTC | |
by salva (Canon) on Sep 20, 2010 at 08:54 UTC | |
|