Skip to content

Comments

Feat/add api guidelines fixed history#23

Merged
TKorr merged 3 commits intomainfrom
feat/add-api-guidelines-fixed-history
Feb 19, 2026
Merged

Feat/add api guidelines fixed history#23
TKorr merged 3 commits intomainfrom
feat/add-api-guidelines-fixed-history

Conversation

@TKorr
Copy link
Contributor

@TKorr TKorr commented Feb 19, 2026

Description

Aligns FixedHistory, SlotArena, and FrequencyBuckets with the
Rust API Guidelines
specifically C-ITER-TY (iterator types are named structs, not impl Iterator)
and C-COMMON-TRAITS (standard trait impls).

FixedHistory<K> (src/ds/fixed_history.rs)

  • Derives Copy — the backing [u64; K] array is always Copy
  • Adds hand-rolled PartialEq, Eq, and Hash that compare logical MRU content
    rather than raw backing-array state (stale slots are invisible to equality/hashing)
  • Adds iter() -> Iter<'_, K> for borrowed iteration in MRU order
  • Implements IntoIterator for both FixedHistory<K> (owned → IntoIter<K>) and
    &FixedHistory<K> (borrowed → Iter<'_, K>)
  • Both iterator types implement ExactSizeIterator

SlotArena<T> (src/ds/slot_arena.rs)

  • iter() now returns the named Iter<'_, T> struct instead of impl Iterator,
    making the type nameable by downstream code

FrequencyBuckets<K> / FrequencyBucketsHandle<H> (src/ds/frequency_buckets.rs)

  • iter_entries() now returns the named EntryIter<'_, K> struct
  • Derives Debug on FrequencyBucketIdIter and FrequencyBucketEntryIter
  • Adds FrequencyBucketsHandle::into_inner() to unwrap the handle back to the
    inner FrequencyBuckets<H>
  • Updates module-level doc tables to use intra-doc links throughout

Related Issue

Fixes #

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to change)
  • 📝 Documentation update
  • 🔧 Refactoring (no functional changes)
  • ⚡ Performance improvement
  • 🧪 Test addition or modification

Breaking: SlotArena::iter(), FrequencyBuckets::iter_entries(), and
FrequencyBucketsHandle::iter_entries() now return named concrete types instead
of impl Iterator. Code that stored the iterator in a typed binding or threaded
the type through a generic will need to update to the new names (Iter,
EntryIter). Callers that simply iterate in a for loop or call .collect()
are unaffected.

How Has This Been Tested?

  • Unit tests
  • Integration tests
  • Manual testing

New tests added in fixed_history.rs:

Test What it covers
iter_yields_mru_order Basic MRU ordering
iter_on_empty / iter_on_zero_capacity Edge cases
iter_after_wrap Correct ordering after ring wraps
iter_partially_filled Sub-capacity buffer
iter_count_matches_len Iterator length invariant
iter_exact_size ExactSizeIterator contract
iter_matches_to_vec_mru Parity with existing to_vec_mru
ref_into_iter_for_loop &FixedHistory in for loop without consuming
owned_into_iter_for_loop Owned IntoIterator
partial_eq_* Logical equality across cursor positions
hash_equal_histories_same_hash Same logical content → same hash
hash_usable_in_hashmap Works as HashMap key
copy_produces_independent_value Copy doesn't alias
copy_can_be_passed_by_value Can pass by value multiple times

Test environment:

  • OS: macOS 15
  • Rust version: stable

Checklist

  • My code follows the project's coding standards
  • I have run cargo fmt and cargo clippy
  • I have added tests for my changes
  • All new and existing tests pass (cargo test)
  • I have updated the documentation as needed
  • I have added an entry to CHANGELOG.md (if applicable)

Additional Notes

The PartialEq/Hash implementations on FixedHistory deliberately iterate
through kth_most_recent rather than comparing the raw data array — two
histories with identical logical content but different cursor positions (e.g. one
that has wrapped) correctly compare equal and produce the same hash. This is
verified by hash_equal_histories_same_hash.

…ements

- Introduced `Iter` and `IntoIter` types for iterating over timestamps in most-recently-used (MRU) order, enhancing usability.
- Updated documentation to include detailed operation tables with method references, improving clarity and navigation.
- Added examples for the new iterator methods, demonstrating their usage in practical scenarios.
- Refined `FixedHistory` struct to derive `Copy`, ensuring lightweight copies in concurrent contexts.
- Implemented `PartialEq`, `Eq`, and `Hash` traits for `FixedHistory`, allowing logical content comparison and hashability.
…provements

- Introduced `EntryIter` for iterating over all entries in `FrequencyBuckets`, yielding tracked entries in unspecified order.
- Updated documentation to include method references in the operations table, improving clarity and navigation.
- Added examples for the new `into_inner` method, demonstrating its usage in practical scenarios.
- Refined iterator implementations in `SlotArena` to enhance usability and maintain performance efficiency.
@TKorr TKorr self-assigned this Feb 19, 2026
@TKorr TKorr merged commit 990cd63 into main Feb 19, 2026
16 checks passed
@TKorr TKorr deleted the feat/add-api-guidelines-fixed-history branch February 19, 2026 17:04
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.

1 participant