Skip to content

feat: add SlidingWindowAggregator, a ring buffer with windowed aggregation - #7591

Merged
DenizAltunkapan merged 1 commit into
TheAlgorithms:masterfrom
alxkm:feat/sliding-window-aggregator
Sep 6, 2026
Merged

feat: add SlidingWindowAggregator, a ring buffer with windowed aggregation#7591
DenizAltunkapan merged 1 commit into
TheAlgorithms:masterfrom
alxkm:feat/sliding-window-aggregator

Conversation

@alxkm

@alxkm alxkm commented Sep 5, 2026

Copy link
Copy Markdown
Member

A fixed-capacity circular buffer that additionally keeps an aggregate of every element it currently holds, so a sliding window sum, minimum or maximum is available in constant time.

Rather than the usual "add the new value, subtract the evicted one" trick, which only works for invertible operators, it uses the two-stack sliding window aggregation algorithm: the window is split into a front section holding suffix aggregates and a back section summarised by a single running aggregate. Every element takes part in at most one rotation between the two, which makes insertion and removal O(1) amortised with no allocation after construction. Any associative operator works, commutative or not, and no identity element is needed.

Comes with factories for sum, minimum and maximum, indexed access, a fail-fast iterator, and tests that check the aggregate against a brute force reference under randomly interleaved insertions and removals.

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized it.
  • All filenames are in PascalCase.
  • All functions and variable names follow Java naming conventions.
  • All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations.
  • All new algorithms include a corresponding test class that validates their functionality.
  • All new code is formatted with clang-format -i --style=file path/to/your/file.java

@codecov-commenter

codecov-commenter commented Sep 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.74%. Comparing base (0a6c756) to head (e3c7798).

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #7591      +/-   ##
============================================
+ Coverage     80.68%   80.74%   +0.06%     
- Complexity     7529     7573      +44     
============================================
  Files           817      818       +1     
  Lines         24162    24257      +95     
  Branches       4759     4772      +13     
============================================
+ Hits          19494    19587      +93     
- Misses         3906     3907       +1     
- Partials        762      763       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…ation

A fixed-capacity circular buffer that additionally keeps an aggregate of
every element it currently holds, so a sliding window sum, minimum or
maximum is available in constant time.

Rather than the usual "add the new value, subtract the evicted one"
trick, which only works for invertible operators, it uses the two-stack
sliding window aggregation algorithm: the window is split into a front
section holding suffix aggregates and a back section summarised by a
single running aggregate. Every element takes part in at most one
rotation between the two, which makes insertion and removal O(1)
amortised with no allocation after construction. Any associative
operator works, commutative or not, and no identity element is needed.

Comes with factories for sum, minimum and maximum, indexed access, a
fail-fast iterator, and tests that check the aggregate against a brute
force reference under randomly interleaved insertions and removals.

Co-authored-by: Oleksandr Klymenko <19151554+alxkm@users.noreply.github.com>
Signed-off-by: alxkm <19151554+alxkm@users.noreply.github.com>
@alxkm
alxkm force-pushed the feat/sliding-window-aggregator branch from 53a6109 to e3c7798 Compare September 5, 2026 20:18
@DenizAltunkapan

Copy link
Copy Markdown
Member

@alxkm thanks!

@DenizAltunkapan
DenizAltunkapan merged commit 14c8db8 into TheAlgorithms:master Sep 6, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants