Skip to content

feat(data-structures/unstable): add Readonly view and clone path to RollingCounter#7161

Open
tomas-zijdemans wants to merge 3 commits into
denoland:mainfrom
tomas-zijdemans:rolling-counter-ready
Open

feat(data-structures/unstable): add Readonly view and clone path to RollingCounter#7161
tomas-zijdemans wants to merge 3 commits into
denoland:mainfrom
tomas-zijdemans:rolling-counter-ready

Conversation

@tomas-zijdemans

Copy link
Copy Markdown
Contributor

Two additive changes, each adopting a pattern already used by sibling data structures.

  • Add ReadonlyRollingCounter, a Pick<> view of the non-mutating members. RollingCounter now implements ReadonlyRollingCounter for a compile-time guarantee. Matches ReadonlyDeque and ReadonlyIndexedHeap.
  • Widen RollingCounter.from() to accept a RollingCounter in addition to a RollingCounterSnapshot. The instance path produces an independent clone with a canonical layout (segments oldest-to-newest, cursor at the last position). Matches Deque.from(deque) and IndexedHeap.from(otherHeap).

No behavior changes for existing call sites.

@tomas-zijdemans tomas-zijdemans changed the title feat(data-structures/unstable): add Readonly view and clone path to ´RollingCounter´ feat(data-structures/unstable): add Readonly view and clone path to RollingCounter May 27, 2026
@codecov

codecov Bot commented May 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.84%. Comparing base (0e5b1f2) to head (1f70590).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7161   +/-   ##
=======================================
  Coverage   94.83%   94.84%           
=======================================
  Files         617      618    +1     
  Lines       51674    51685   +11     
  Branches     9350     9352    +2     
=======================================
+ Hits        49007    49019   +12     
  Misses       2121     2121           
+ Partials      546      545    -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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@bartlomieju bartlomieju left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean, idiomatic, and well-tested — it mirrors the ReadonlyDeque / Deque.from(deque) precedent member-for-member. I verified the clone equals from(source.toJSON()), is fully independent (#segments reallocated, #total copied), the Pick includes exactly the non-mutating members, and the whole suite + doc examples pass on the branch. The error-message change ("snapshot""source") is safe since the throw tests assert error types, not text.

Approving. Two optional polish notes inline; neither is a blocker.

Comment thread data_structures/unstable_rolling_counter.ts Outdated
Comment thread data_structures/unstable_rolling_counter_test.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants