A node process of mine receives a sample point every half a second, and I want to update the history chart of all the sample points I receive.The chart should be an array which contains the downsampled history of all points from 0 to the current point.In other words, the maximum length of the array should be l. If I received more sample points than l, I want the chart array to be a downsampled-to-l version of the whole history.To express it with code (examples are in javascript but the question is language agnostic):const CHART_LENGTH = 2048createChart(CHART_LENGTH)onReceivePoint = function(p) {    // p can be considered a number    const chart = addPointToChart(p)    // chart is an array representing all the samples received, from 0 to now    console.assert(chart.length <= CHART_LENGTH)}I already have a working downsampling function with number arrays:function downsample (arr, density) {  let i, j, p, _i, _len  const downsampled = []  for (i = _i = 0, _len = arr.length; _i < _len; i = ++_i) {    p = arr[i]    j = ~~(i / arr.length * density)    if (downsampled[j] == null) downsampled[j] = 0    downsampled[j] += Math.abs(arr[i] * density / arr.length)  }  return downsampled}One trivial way of doing this would obviously be saving all the points I receive into an array, and apply the downsample function whenever the array grows. This would work, but, since this piece of code would run in a server, possibly for months and months in a row, it would eventually make the supporting array grow so much that the process would go out of memory.The question is: Is there an algorithm to construct the chart array re-using the previous contents of the chart itself, to avoid mantaining a growing data structure? In other words, is there a constant memory complexity solution to this problem?Please note that the chart must contain the whole history since sample point #0 at any moment, so charting the last n points would not be acceptable.
Algorithm to efficiently chart endless signal
algorithms;memory;efficiency;big data;chart