On Wed, 12 Feb 2003, Jeffrey Sharp wrote:
On Wednesday, February 12, 2003, Hans Franke wrote:
>> I
don't know anything which can't be done in a megabyte of mem.
> How about a database record sort on a field
with a data length greater
> than 1MB?
HF> read the fields to compare in chunks of max say 64K (well in reality i'd
HF> use the block/cluster size of the drive) and compare it.
Read from where? What drive? You assume too much.
I'd tend to guess that the 1MB fields probably come from the storage
device holding the database... Unless you're assuming that the database
is stored in someone's brain, and that they're toggling in those 1MB
fields on the console switches.
The original problem has the given of there being a database. I think
we can safely assume that there's at least one "table" in the database,
and that within this table there is more than one record--otherwise the
excercise of sorting it would be rather silly--and that those records
have at least one field of 1MB in size. The original problem implied
there were more though, which would make the task more challenging.
The other given is that you've a machine with 1MB of RAM.
So... it very logically /follows/ that this database has to live
somewhere, and it has to live somewhere that's not in RAM. Whether one
assumes it's on a floppy disk, a hard disk, tape drive, paper tape,
punch cards, or that it's being interactively toggled in via the console
switches--the process being suggested for sorting it still holds, albeit
with varying degrees of performance. Hans' assumption of it being disk
I/O based is the most sensible of those options, but the general
approach of his solution is valid with any of the other alternatives.
And if you assume you don't have some sort of I/O channel for accessing
this database, the problem most assuredly won't be with not having
enough RAM!
Actually, there are two other options: (1) the database is entirely in
RAM, it has one table, with one record, with one field of precisely 1MB
in size, or (2) the database has zero records. In either of those
cases, you don't even need to write a sorting program since the tables
are already sorted.
-brian.