0

I am interested in a package that has an interface like:

  • set_latency(date, latency)
  • get_average_latency(5) # returns the latency in the last 5 minutes

Is there a pip package already doing this?

Ryan
  • 5,456
  • 25
  • 71
  • 129
  • Can't you just traverse the list of values backward, checking if the date is in the 5 minute range (check http://stackoverflow.com/a/17191361/2811496)? – hornobster Jul 19 '16 at 12:21
  • it should have an amortized O(1) complexity for get_average_latency, otherwise it is not efficient – Ryan Jul 19 '16 at 12:46
  • Do you need average value for last 5 minutes only or any period query is possible? – MBo Jul 19 '16 at 13:51
  • I don't see how you can get below O(n). You could accumulate all the sums in set_latency (O(N) space and time), but you would still need to find the oldest date within the X range, which is O(logn) with a balanced BST. – hornobster Jul 19 '16 at 14:02

0 Answers0