Add VersionMap utility methods and improve implementation#5
Draft
Add VersionMap utility methods and improve implementation#5
Conversation
This was referenced May 23, 2025
Merged
There was a problem hiding this comment.
Pull Request Overview
This PR enhances the VersionMap with new utility methods for size, emptiness, membership, mutation, and clearing; adds iteration helpers; refactors insertion and alternate tracking; optimizes lookup; and updates tests accordingly.
- Added standard collection methods (
len,is_empty,contains_version,clear,get_mut,get_first) and iteration APIs (versions,iter). - Refactored insertion logic into
insert_internal/update_alternates, implementedDefault, and optimizedgetto try exact match first. - Improved
removeto clean up alternate mappings and expanded test coverage for new behaviors.
Comments suppressed due to low confidence (2)
src/semver.rs:177
- [nitpick] After removing a version from the alternates set, consider removing its key when the set becomes empty to avoid leaving stale entries in
alternates.
set.remove(version);
src/semver.rs:163
- [nitpick] Add a unit test for
get_mutto verify that you can obtain and modify a stored value through a mutable reference.
pub fn get_mut(&mut self, version: &Version) -> Option<&mut T> {
1b678a7 to
e49a816
Compare
e49a816 to
eaf7ef3
Compare
eaf7ef3 to
a96c38a
Compare
2538a12 to
94a291f
Compare
2c69060 to
85fef49
Compare
9b3f645 to
2505633
Compare
85fef49 to
6c01479
Compare
6c01479 to
b2a41b4
Compare
3949476 to
da41053
Compare
da41053 to
d50e930
Compare
d50e930 to
41c9dad
Compare
bae0fd6 to
9807ba2
Compare
9807ba2 to
0d58c29
Compare
0d58c29 to
307fd1f
Compare
Code Coverage Report
Minimum allowed coverage is |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Enhanced VersionMap with Additional Utility Methods
This PR enhances the
VersionMapimplementation with several new utility methods and improves the internal structure:Added standard collection methods:
len(),is_empty(),contains_version()clear()to remove all versionsget_mut()for mutable access to valuesAdded iteration capabilities:
versions()to iterate over all versions in sorted orderiter()to iterate over version-value pairsget_first()to retrieve the lowest version and its valueImproved internal implementation:
DefaultforVersionMapget()method to check for exact match firstremove()to properly clean up alternates mappingAdded comprehensive tests for all new functionality
These changes make
VersionMapmore complete and consistent with standard Rust collection types.