Skip to content

Tracking for map_entry_recover_keys #34285

Closed

Description

@seanmonstar
No description provided.

Activity

  1. added
    T-libs-api
    B-unstable
    on Jun 15, 2016
  2. alexcrichton commented on Jun 15, 2016

    @alexcrichton
    Member

    Specifically covers:

    • VacantEntry::into_key
    • OccupiedEntry::remove_pair

    for both HashMap and BTreeMap.

    I would personally still hesitate a little on the name remove_pair (specifically the pair part) but otherwise seems good to me.

  3. added
    final-comment-period
    and removed on Jul 13, 2016
  4. alexcrichton commented on Jul 13, 2016

    @alexcrichton
    Member

    🔔 This issue is now entering a cycle-long final comment period for stabilization 🔔

    Note though that the libs team isn't entirely comfortable with the name remove_pair, so we'd like to consider other possibilities during this FCP!

  5. seanmonstar commented on Jul 13, 2016

    @seanmonstar
    ContributorAuthor

    I somewhat like impl Into<(K, V)> for OccupiedEntry, so that it's then let mine = occupied.into();.

  6. alexcrichton commented on Jul 13, 2016

    @alexcrichton
    Member

    Sounds like a great fit to me!

  7. Stebalien commented on Jul 23, 2016

    @Stebalien
    Contributor

    Is there any way to recover the key used in the entry from an occupied entry? That is, I'm trying to write a multimap like with the following insert definition:

            let mut key = (key, 0);
            loop {
                match self.values.entry(key) {
                    Entry::Vacant(e) => {
                        let idx = e.key().1;
                        e.insert(value);
                        return idx;
                    },
                    Entry::Occupied(e) => {
                        key = e.??? /* What here? */
                        key.1 += 1;
                    }
                }
            }

    I don't want to remove the key/value pair from the hash-map, I just want my key back!

  8. alexcrichton commented on Jul 23, 2016

    @alexcrichton
    Member

    @Stebalien I believe not currently, no, but it is the subject of an RFC or two

  9. Stebalien commented on Jul 23, 2016

    @Stebalien
    Contributor

    Got it. I just want to make sure the APIs play well together. Specifically, given that we want a way to to move keys out Entry, VacentEntry, and OccupiedEntry, I'd do the following:

    1. Remove VacentEntry::into_key.
    2. Rename remove_pair to remove or take as opposed to replacing it with an Into<(K, V)> implementation.
    3. Add Into<K> implementations for converting entries back into their keys:
    impl Into<K> for Entry {}
    impl Into<K> for OccupiedEntry {}
    impl Into<K> for VacantEntry {}

    Note: I'm proposing (2) because having two different Into impls that do very different things (one mutates the map, the other doesn't is probably a bad idea.

  10. alexcrichton commented on Jul 25, 2016

    @alexcrichton
    Member

    Hm yeah that's actually a good point about Into<(K, V)> having odd behavior by mutating the map. I also agree that if we have key recover it'd be good to be consistent across entry types. Thanks for the good points @Stebalien!

  11. Stebalien commented on Jul 25, 2016

    @Stebalien
    Contributor

    We can't actually write those Into impls due to coherence... 😢.

  12. alexcrichton commented on Aug 11, 2016

    @alexcrichton
    Member

    The libs team discussed this recently and concluded:

    • It does seem odd to use Into for removal from the map, so we'd prefer to avoid.
    • Eventually adding Into seems good, but perhaps not necessary immediately
    • VacantEntry::into_key seems good enough for now, we can always add Into<K> later if necessary.
    • The remove method is unfortunately already taken
    • The take method is used on HashSet, setting precedent, but the semantics are removal for a mutable container, not consumption of the container (e.g. Option::take as well)
    • Another more plausible name for removal is remove_entry

    As a result our conclusions were:

    • Let's add into_key, looking to add Into<K> later if necessary
    • Let's name the removal method remove_entry
  13. added a commit that references this issue on Aug 18, 2016
    7f38beb
  14. added a commit that references this issue on Aug 20, 2016
    99867ee
  15. added a commit that references this issue on Aug 23, 2016
    4ce3c86
  16. added a commit that references this issue on Sep 27, 2016
    1076a3d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    B-unstableT-libs-apifinal-comment-period

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions