CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Intermediate: Re: [FishMonger] iterate over millions hash entries: Edit Log

New User

Apr 13, 2017, 7:15 AM

Views: 8437
Re: [FishMonger] iterate over millions hash entries

In Reply To
You could invert the hash so that the keys are the numbers and the values are array refs of your current keys.

For example, instead of this hash structure:

%hash = ( 
'foo' => 10,
'bar' => 30,
'baz' => 10,

You'd have:

%hash = ( 
10 => [ 'foo', 'baz' ],
30 => [ 'bar' ],

Then do a normal/typical sort on the keys.

i dont understand why inverting the hash will accelerate the iteration and sorting, except it could reduce the hash size for keys with same value but in my program it will not be the case

(This post was edited by skualito92 on Apr 13, 2017, 7:17 AM)

Edit Log:
Post edited by skualito92 (New User) on Apr 13, 2017, 7:17 AM

Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives