Hacker News new | past | comments | ask | show | jobs | submit login
Purely Functional Sliding Window Aggregation Algorithm (byorgey.github.io)
24 points by agnishom 6 hours ago | hide | past | favorite | 3 comments





This is similar to an approach I use but instead of a queue, I accomplish this using a ring buffer that wraps around and overwrites entries older than window size. We maintain a global window aggregate, subtract ring buffer slot aggregate for entries dropping out and accumulate new entries into new slot aggregate while adding it to the global aggregate. Everything is o(1) including reads, which just returns the global window aggregate.

This is a very interesting algorithm which is more or less known in the folklore, but is still relatively obscure. I have used it as a part of temporal logic monitoring procedure: https://github.com/Agnishom/lattice-mtl/blob/master/src/Moni...

Not sure I'd call it obscure: https://leetcode.com/problems/maximum-subarray/

I've seen it in tech interviews for years.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: