Skip to content

Instantly share code, notes, and snippets.

@heuristicus
Created August 13, 2011 20:15
Show Gist options
  • Select an option

  • Save heuristicus/1144209 to your computer and use it in GitHub Desktop.

Select an option

Save heuristicus/1144209 to your computer and use it in GitHub Desktop.
Idea for a little project that could be vaguely useful.
Program that takes n folders/files and m devices with storage capacity and decides the best way to distribute files among them to best fill the given devices.
How best to fill devices is debatable, but let's assume that you want to use as much space on each device as possible.
Program would try and keep folders together - option to ignore folder structure and maximise the amount of fill?
Could move each stack into a separate folder to indicate the device it should go on to, if the user does not/cannot plug in all devices.
Method:
Probably quite difficult to use a simple method for a large number of files.
First thing that comes to mind is using a dict to store the file name, file size and parent of each file, and then somehow use that structure to lump stuff together. This kind of thing would probably lead to some sort of pair comparison, or something along that line of complexity - at least, if you were matching file sizes to see how close each got to each device size. That is also problematic because if you find one stack that is very good, then you have to remove the files in that stack from all other potential stacks which is probably quite inefficient.
Some sort of method using a list or graph seems like it could be an efficient way of computing good stacks, but this is probably wrong - I think you need some sort of algorithm which will do things without really using a data structure as such.
A good method might be to start by 'stacking' all folders and files which have a small file size to try and fill the device, but this may turn out to not be the best solution in some cases.
Will need to keep track of the size of the current 'stack' size, and the size remaining on all the devices. When the stack gets close to the size of one of the devices, assign that stack to be transferred to that device? Leads to some potential inefficiency - if you're stacking from the smallest to largest, and fill the device with most space first this leads to problems. However, if you assign when you get a value close to the remaining space, then logically the device with least space will be assigned to first. More problems - if you use up all the small files when there is a file that by itself gives you a good fill then you waste potential for good filling on other devices by using up all the small files.
If there is a large file and a device with a large amount of space on it, then put the large file into that device, as long as it does not fit the size of another device more closely? Seems like this would only really apply if the file will not fit on one of the devices.
System must define what a large file is, given the sizes of the devices and the sizes of the files it is dealing with.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment