Hi,<br><br>I have a list of index-value pairs and I want to get a list
which is sorted by the index and which contains index-wise sums of all the values.<br>Here is a function that does this (and a bit more).<br>---<br>
pixelHistogram samples = let<br> index s t = let<br> x = round $ (fromIntegral imageWidth) * (1-s)<br> y = round $ (fromIntegral imageHeight) * (1-t)<br> in y*imageWidth + x<br> indexedSamples = [(index s t, color) | (s, t, color) <- samples]<br>
pixelArray :: Array Int Color<br> pixelArray = accumArray (\+) black (0, imageWidth*imageHeight) indexedSamples <br> in elems pixelArray<br>---<br><br>The
problem is that this function is very inefficient. It seems that the
whole indexedSamples list is stored in memory when creating pixelArray.<br>
When I do some profiling I see that the heap consumption of this function grows linearly. <br>If I just write the samples list to a file instead of first summing them, I get a nice and flat heap profile.<br><br>So how to do this efficiently?<br>
<br>Thanks,<br><font color="#888888">
Lauri</font>