Skip to content

Tracking for map_entry_recover_keys #34285

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
seanmonstar opened this issue Jun 15, 2016 · 10 comments
Closed

Tracking for map_entry_recover_keys #34285

seanmonstar opened this issue Jun 15, 2016 · 10 comments
Labels
B-unstable Blocker: Implemented in the nightly compiler and unstable. final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@seanmonstar
Copy link
Contributor

No description provided.

@alexcrichton alexcrichton added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. B-unstable Blocker: Implemented in the nightly compiler and unstable. labels Jun 15, 2016
@alexcrichton
Copy link
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.

@alexcrichton alexcrichton added final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. and removed I-nominated labels Jul 13, 2016
@alexcrichton
Copy link
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!

@seanmonstar
Copy link
Contributor Author

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

@alexcrichton
Copy link
Member

Sounds like a great fit to me!

@Stebalien
Copy link
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!

@alexcrichton
Copy link
Member

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

@Stebalien
Copy link
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.

@alexcrichton
Copy link
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!

@Stebalien
Copy link
Contributor

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

@alexcrichton
Copy link
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

alexcrichton added a commit to alexcrichton/rust that referenced this issue Aug 18, 2016
Stabilized

* `Cell::as_ptr`
* `RefCell::as_ptr`
* `IpAddr::is_{unspecified,loopback,multicast}`
* `Ipv6Addr::octets`
* `LinkedList::contains`
* `VecDeque::contains`
* `ExitStatusExt::from_raw` - both on Unix and Windows
* `Receiver::recv_timeout`
* `RecvTimeoutError`
* `BinaryHeap::peek_mut`
* `PeekMut`
* `iter::Product`
* `iter::Sum`
* `OccupiedEntry::remove_entry`
* `VacantEntry::into_key`

Deprecated

* `Cell::as_unsafe_cell`
* `RefCell::as_unsafe_cell`
* `OccupiedEntry::remove_pair`

Closes rust-lang#27708
cc rust-lang#27709
Closes rust-lang#32313
Closes rust-lang#32630
Closes rust-lang#32713
Closes rust-lang#34029
Closes rust-lang#34392
Closes rust-lang#34285
Closes rust-lang#34529
bors added a commit that referenced this issue Aug 18, 2016
std: Stabilize APIs for the 1.12 release

Stabilized

* `Cell::as_ptr`
* `RefCell::as_ptr`
* `IpAddr::is_{unspecified,loopback,multicast}`
* `Ipv6Addr::octets`
* `LinkedList::contains`
* `VecDeque::contains`
* `ExitStatusExt::from_raw` - both on Unix and Windows
* `Receiver::recv_timeout`
* `RecvTimeoutError`
* `BinaryHeap::peek_mut`
* `PeekMut`
* `iter::Product`
* `iter::Sum`
* `OccupiedEntry::remove_entry`
* `VacantEntry::into_key`

Deprecated

* `Cell::as_unsafe_cell`
* `RefCell::as_unsafe_cell`
* `OccupiedEntry::remove_pair`

Closes #27708
cc #27709
Closes #32313
Closes #32630
Closes #32713
Closes #34029
Closes #34392
Closes #34285
Closes #34529
alexcrichton added a commit to alexcrichton/rust that referenced this issue Aug 19, 2016
Stabilized

* `Cell::as_ptr`
* `RefCell::as_ptr`
* `IpAddr::is_{unspecified,loopback,multicast}`
* `Ipv6Addr::octets`
* `LinkedList::contains`
* `VecDeque::contains`
* `ExitStatusExt::from_raw` - both on Unix and Windows
* `Receiver::recv_timeout`
* `RecvTimeoutError`
* `BinaryHeap::peek_mut`
* `PeekMut`
* `iter::Product`
* `iter::Sum`
* `OccupiedEntry::remove_entry`
* `VacantEntry::into_key`

Deprecated

* `Cell::as_unsafe_cell`
* `RefCell::as_unsafe_cell`
* `OccupiedEntry::remove_pair`

Closes rust-lang#27708
cc rust-lang#27709
Closes rust-lang#32313
Closes rust-lang#32630
Closes rust-lang#32713
Closes rust-lang#34029
Closes rust-lang#34392
Closes rust-lang#34285
Closes rust-lang#34529
bors added a commit that referenced this issue Aug 20, 2016
std: Stabilize APIs for the 1.12 release

Stabilized

* `Cell::as_ptr`
* `RefCell::as_ptr`
* `IpAddr::is_{unspecified,loopback,multicast}`
* `Ipv6Addr::octets`
* `LinkedList::contains`
* `VecDeque::contains`
* `ExitStatusExt::from_raw` - both on Unix and Windows
* `Receiver::recv_timeout`
* `RecvTimeoutError`
* `BinaryHeap::peek_mut`
* `PeekMut`
* `iter::Product`
* `iter::Sum`
* `OccupiedEntry::remove_entry`
* `VacantEntry::into_key`

Deprecated

* `Cell::as_unsafe_cell`
* `RefCell::as_unsafe_cell`
* `OccupiedEntry::remove_pair`

Closes #27708
cc #27709
Closes #32313
Closes #32630
Closes #32713
Closes #34029
Closes #34392
Closes #34285
Closes #34529
alexcrichton added a commit to alexcrichton/rust that referenced this issue Aug 23, 2016
Stabilized

* `Cell::as_ptr`
* `RefCell::as_ptr`
* `IpAddr::is_{unspecified,loopback,multicast}`
* `Ipv6Addr::octets`
* `LinkedList::contains`
* `VecDeque::contains`
* `ExitStatusExt::from_raw` - both on Unix and Windows
* `Receiver::recv_timeout`
* `RecvTimeoutError`
* `BinaryHeap::peek_mut`
* `PeekMut`
* `iter::Product`
* `iter::Sum`
* `OccupiedEntry::remove_entry`
* `VacantEntry::into_key`

Deprecated

* `Cell::as_unsafe_cell`
* `RefCell::as_unsafe_cell`
* `OccupiedEntry::remove_pair`

Closes rust-lang#27708
cc rust-lang#27709
Closes rust-lang#32313
Closes rust-lang#32630
Closes rust-lang#32713
Closes rust-lang#34029
Closes rust-lang#34392
Closes rust-lang#34285
Closes rust-lang#34529
pmatos pushed a commit to LinkiTools/rust that referenced this issue Sep 27, 2016
Stabilized

* `Cell::as_ptr`
* `RefCell::as_ptr`
* `IpAddr::is_{unspecified,loopback,multicast}`
* `Ipv6Addr::octets`
* `LinkedList::contains`
* `VecDeque::contains`
* `ExitStatusExt::from_raw` - both on Unix and Windows
* `Receiver::recv_timeout`
* `RecvTimeoutError`
* `BinaryHeap::peek_mut`
* `PeekMut`
* `iter::Product`
* `iter::Sum`
* `OccupiedEntry::remove_entry`
* `VacantEntry::into_key`

Deprecated

* `Cell::as_unsafe_cell`
* `RefCell::as_unsafe_cell`
* `OccupiedEntry::remove_pair`

Closes rust-lang#27708
cc rust-lang#27709
Closes rust-lang#32313
Closes rust-lang#32630
Closes rust-lang#32713
Closes rust-lang#34029
Closes rust-lang#34392
Closes rust-lang#34285
Closes rust-lang#34529
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
B-unstable Blocker: Implemented in the nightly compiler and unstable. final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants