Skip to content

feat: add TimestampOrderChecker, out of order and duplicate timestamps - #7733

Open
alxkm wants to merge 3 commits into
TheAlgorithms:masterfrom
alxkm:feat/timestamp-order-checker
Open

alxkm wants to merge 3 commits into
TheAlgorithms:masterfrom
alxkm:feat/timestamp-order-checker

Conversation

@alxkm

@alxkm alxkm commented Nov 7, 2026

Copy link
Copy Markdown
Member

Adds TimestampOrderChecker to the streaming package. It checks each timestamp against the previous one and reports it as increasing, duplicate or backwards. It does not reorder or drop anything. It also keeps the worst backwards step, which tells you how big a reordering buffer would need to be to fix the stream. O(1) per sample.

  • 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 Nov 7, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.77778% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 82.37%. Comparing base (c3ce690) to head (8cbc088).

Files with missing lines Patch % Lines
...thealgorithms/streaming/TimestampOrderChecker.java 97.77% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #7733      +/-   ##
============================================
+ Coverage     82.34%   82.37%   +0.03%     
- Complexity     8447     8467      +20     
============================================
  Files           843      844       +1     
  Lines         26156    26201      +45     
  Branches       5110     5115       +5     
============================================
+ Hits          21538    21583      +45     
  Misses         3830     3830              
  Partials        788      788              

☔ 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.

@alxkm
alxkm marked this pull request as ready for review November 7, 2026 09:57
Windowed algorithms assume time moves forward. When it does not, nothing fails loudly: a window holds samples that never coexisted, a rate is computed over a negative interval, a duplicate is counted twice. Retries, buffers flushed after a reconnect, several producers writing into one topic and a clock stepped backwards all cause this, and the cheap defence is to check the order explicitly.

Each timestamp is compared with the previous one and classified as INCREASING, DUPLICATE or BACKWARDS. The checker only reports, it does not reorder or drop anything, so lastTimestamp is always the most recent sample, not the largest. It also keeps the worst backwards step, which is what you need to size a reordering buffer. O(1) time per sample and O(1) state; non-finite timestamps are refused.

Tests: the first timestamp is always accepted, an ordered stream has no violations, duplicates and backwards steps are counted separately, the worst step is the largest one and not the last one, the stream is not reordered, scan returns one verdict per timestamp, and reset restores the initial state.

Signed-off-by: alxkm <19151554+alxkm@users.noreply.github.com>
@alxkm
alxkm force-pushed the feat/timestamp-order-checker branch from ea480b2 to 4ba6857 Compare November 7, 2026 09:59
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.

2 participants