Add iter(), iter_mut(), drain(), and clear() - #5
Conversation
📝 WalkthroughWalkthroughThis PR extends ChangesSparseMap iteration and bulk removal APIs
🎯 3 (Moderate) | ⏱️ ~25 minutes
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
iter(), iter_mut(), drain(), and clear()
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/lib.rs`:
- Around line 594-596: Several test cases call map.insert(...) and ignore its
#[must_use] return (a Key), causing clippy failures; update each call to either
capture the returned Key into a variable prefixed with _ (e.g., let _key =
map.insert(...);) or use the Key in assertions so the value is consumed. Search
for direct calls to map.insert in the tests (examples around the repeated
patterns inserting 1,2,3) and replace the bare calls with bound results (or
assert on them) to satisfy the must_use requirement.
- Around line 252-275: The bulk-removal paths (clear and drain) currently only
bump generations for slots where slot.take().is_some(), missing slots that are
"temporarily empty" (reserved via take()/scope()) so outstanding Key::restore()
can still succeed; update clear and Drain::drop (the drain implementation) to
treat any non-empty placeholder (i.e., any slot that is not the canonical Empty
variant) as a live slot that must have its generation bumped and be reclaimed:
iterate buffer entries and for each slot that is not Empty (including
reserved/placeholder states created by take()/scope()), increment
self.generations[index] (wrapping_add(1)), ensure the slot is set to Empty and
add its index to empty_slots so the map is truly emptied and Keys are
invalidated; apply the same logic to the drain() implementation and the
symmetric code block noted around the other range (the second occurrence) so
restore()/scope() can no longer resurrect values after clear()/drain().
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 9f136536-5c97-4f62-a234-692b495692ba
⛔ Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (2)
Cargo.tomlsrc/lib.rs
iter()&iter_mut()to iterate through the entire map (unordered)drain()to drain the entire map while iterating through the values.clear()to clear all values and invalidate existing keys (via generation incrementation).