[Tutor] Generate list-of-transforms

R. Alan Monroe amonroe at columbus.rr.com
Fri Dec 6 01:53:28 CET 2013


> What does the OP actually want?

I started writing another fake defrag program to entertain myself in a
little downtime at work. The FAT-styled "drive" is just a Python list
of integers where each element points to the the next "block" of the
fictitious "file", with the last element of any given file being None.
A dict tracks the filenames and starting blocks of files.

I managed to get this far:

1. Fill up the first drive with a series of randomly sized writes and
deletes.

2. Fill up a second drive with the files from the first drive,
sequentially in descending order by size. This would be the ideal
state of the first drive, once it's defragged.

By comparing the two drives I know that the 13th block of file91, for
example, lives at 233 on the fragged drive, but the idealized drive
shows me that the 13th block of file91 lives at 124.

Now I'm here:

A straight 1-to-1 swap isn't going to work, because whatever is
currently at 124 has a low likelihood of being destined to live at
233. All I have to work with is the current and destined positions of
every piece of every file.

Furthermore, since this is just for practice and aesthetic purposes, I
want the block moves to be semirandom rather than evacuating space at
the head of the drive for the first file, then evacuating space after
that for the second file, and so on like a traditional defrag. Rather
I'd like something that gives the appearance of a computer-generated
Rubik's cube solution, where everything seemingly comes together in
the last few moves.

Alan



More information about the Tutor mailing list