Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: An APL trick for the Schwartzian Transform

by diotalevi (Canon)
on Nov 14, 2002 at 14:39 UTC ( [id://212844]=note: print w/replies, xml ) Need Help??


in reply to An APL trick for the Schwartzian Transform

Neat. Only very rarely have I actually cared about perl's memory usage and probably all five times it's been for a very large sorting job. (I define large as being four times the size of memory, in this case two one gig text files). I've often found Knuth's The Art of Computer Programming vol 2, Sorting and Searching to be an excellent source of ideas when the common sort() isn't good enough. I recommend it as an excellent resource for ideas.

For actual solutions I normally look for things like a disk-base db file (usually BerkeleyDB) for an external sort or some variation on partitioning and/or radix sort. My favorite and least effort trick when sorting voting records from the Secretary of State (by precinct and by voter id) just involves doing a combination of a radix and external sort: find a key field (I choose voting precinct) that can partition the data into appropriate sized bins and do just insert into the appropriate files (one per precinct).

Once all the files are complete I do an in-memory plain-jane sort() on the data and write it back out over the previously unsorted partition. At this point I can either stop and decide to access the data from the individual partitions as-is or just cat(1) the files together and recreate a full (approximately 1 gig) text file. That's only a scetch but there are plenty of other great ideas in just the sorting section of TAoCP. It's worth checking out.

Pre-publication update: broquaint pointed me to the excellent node resorting to sorting which does a nice overview of some common sorts.

__SIG__ use B; printf "You are here %08x\n", unpack "L!", unpack "P4", pack "L!", B::svref_2object(sub{})->OUTSIDE;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://212844]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (4)
As of 2024-04-19 13:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found