Skip to content

Conversation

@billf
Copy link
Contributor

@billf billf commented May 23, 2025

Enhanced VersionMap with Additional Utility Methods

This PR enhances the VersionMap implementation with several new utility methods and improves the internal structure:

  • Added standard collection methods:

    • len(), is_empty(), contains_version()
    • clear() to remove all versions
    • get_mut() for mutable access to values
  • Added iteration capabilities:

    • versions() to iterate over all versions in sorted order
    • iter() to iterate over version-value pairs
    • get_first() to retrieve the lowest version and its value
  • Improved internal implementation:

    • Implemented Default for VersionMap
    • Refactored insertion logic with helper methods
    • Optimized get() method to check for exact match first
    • Enhanced remove() to properly clean up alternates mapping
  • Added comprehensive tests for all new functionality

These changes make VersionMap more complete and consistent with standard Rust collection types.

Copy link
Contributor Author

billf commented May 23, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

@billf billf requested a review from Copilot May 23, 2025 16:21
@billf billf marked this pull request as ready for review May 23, 2025 16:21
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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, implemented Default, and optimized get to try exact match first.
  • Improved remove to 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_mut to 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> {

@billf billf force-pushed the billf/semver/feature branch from 1b678a7 to e49a816 Compare May 23, 2025 22:08
@billf billf force-pushed the billf/semver/test branch from 51dbaa4 to 17b55a3 Compare May 23, 2025 22:08
@billf billf force-pushed the billf/semver/feature branch from e49a816 to eaf7ef3 Compare May 23, 2025 22:19
@billf billf force-pushed the billf/semver/test branch from 17b55a3 to cb10ffc Compare May 23, 2025 22:19
@billf billf marked this pull request as draft May 23, 2025 22:51
@billf billf force-pushed the billf/semver/feature branch from eaf7ef3 to a96c38a Compare May 29, 2025 02:00
@billf billf force-pushed the billf/semver/test branch 2 times, most recently from 2538a12 to 94a291f Compare May 29, 2025 18:48
@billf billf force-pushed the billf/semver/feature branch 2 times, most recently from 2c69060 to 85fef49 Compare May 29, 2025 19:50
@billf billf force-pushed the billf/semver/test branch 2 times, most recently from 9b3f645 to 2505633 Compare May 29, 2025 21:15
@billf billf force-pushed the billf/semver/feature branch from 85fef49 to 6c01479 Compare May 29, 2025 21:15
@billf billf requested a review from a team May 29, 2025 21:18
@billf billf self-assigned this May 29, 2025
@billf billf force-pushed the billf/semver/test branch from 2505633 to bd3f3b5 Compare May 29, 2025 22:54
@billf billf force-pushed the billf/semver/feature branch from 6c01479 to b2a41b4 Compare May 29, 2025 22:54
@billf billf force-pushed the billf/semver/test branch from bd3f3b5 to eb4576e Compare May 30, 2025 20:46
@billf billf force-pushed the billf/semver/feature branch 2 times, most recently from 3949476 to da41053 Compare May 30, 2025 22:23
@billf billf force-pushed the billf/semver/test branch from eb4576e to bac0782 Compare May 30, 2025 22:23
@billf billf force-pushed the billf/semver/feature branch from da41053 to d50e930 Compare May 31, 2025 01:25
@billf billf force-pushed the billf/semver/test branch from bac0782 to 03ade8b Compare May 31, 2025 01:25
@billf billf changed the base branch from billf/semver/test to graphite-base/5 June 3, 2025 18:38
@billf billf force-pushed the graphite-base/5 branch from 03ade8b to a33b9ad Compare June 3, 2025 19:13
@billf billf force-pushed the billf/semver/feature branch from d50e930 to 41c9dad Compare June 3, 2025 19:13
@billf billf changed the base branch from graphite-base/5 to billf/semver/test June 3, 2025 19:13
@billf billf force-pushed the billf/semver/test branch from a33b9ad to 84e2f75 Compare June 3, 2025 23:43
@billf billf force-pushed the billf/semver/feature branch 2 times, most recently from bae0fd6 to 9807ba2 Compare June 10, 2025 16:49
@billf billf changed the base branch from billf/semver/test to graphite-base/5 June 18, 2025 21:52
@billf billf force-pushed the billf/semver/feature branch from 9807ba2 to 0d58c29 Compare June 18, 2025 21:52
@billf billf changed the base branch from graphite-base/5 to master June 18, 2025 21:53
@billf billf force-pushed the billf/semver/feature branch from 0d58c29 to 307fd1f Compare June 19, 2025 01:00
@github-actions
Copy link

Code Coverage Report

Package Base Coverage New Coverage Difference
graph.rs 🟢 81.85% 🟢 81.85% ⚪ 0%
path.rs 🟢 100% 🟢 100% ⚪ 0%
semver.rs 🟢 97.7% 🟠 69.51% 🔴 -28.19%
trampoline.rs 🟠 72.86% 🟠 72.86% ⚪ 0%
Overall Coverage 🟢 85.77% 🟢 80.41% 🔴 -5.36%

Minimum allowed coverage is 0%, this run produced 80.41%

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