[Gllug] OT: algorithm needed

Dylan dylan at dylan.me.uk
Sun Aug 10 20:49:23 UTC 2008


On Sunday 10 August 2008, salsaman at xs4all.nl wrote:
> Hi,
> here is one for the maths lovers.
>
> I am trying to devise an algorithm to read in blocks from disk. There is a
> total read size, and a max block size.
>
> On each read I read in max_block_size or less bytes, until the total is
> reached.
>
> However, I want the last read to be as close to max_block_size as possible.
>
> E.g. if total==100, max==45, I could read:
>
> 45, 45, 10.
>
> However it would be preferable to read:
>
> 40, 40, 20, or better yet:
>
> 35, 35, 30
>

Take the average block size, round it up and subtract the excess from the 
total of the last block, or round it down and use the excess to make a final 
block.

It's simple, but won't be optimum, and could subtract or add more than one 
block.

Dx
-- 
“ ‘... but there is so much else behind what I say. It makes itself known to 
me so slowly, so incompletely! ...’ ”
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug


More information about the GLLUG mailing list