Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Map::retain #1338

Closed
2 tasks done
Gankra opened this issue Oct 27, 2015 · 9 comments
Closed
2 tasks done

Map::retain #1338

Gankra opened this issue Oct 27, 2015 · 9 comments
Labels
A-collections Proposals about collection APIs T-libs-api Relevant to the library API team, which will review and decide on the RFC.

Comments

@Gankra
Copy link
Contributor

Gankra commented Oct 27, 2015

Like Vec::retain but for Maps.

@aji
Copy link

aji commented Oct 27, 2015

👍 this would be excellent

@nrc nrc added the T-libs-api Relevant to the library API team, which will review and decide on the RFC. label Aug 19, 2016
@mbrubeck
Copy link
Contributor

This was implemented for HashMap (but not BTreeMap) in rust-lang/rust#39560.

@Centril
Copy link
Contributor

Centril commented Oct 7, 2018

Triage, @SimonSapin can/should we perhaps do this for BTreeMap as well if possible?

@jeffparsons
Copy link
Contributor

The use case I have for this would be to selectively remove elements within a given range — and I'm guessing that's pretty common. Making the interface work for that would be a bit harder than what was implemented for HashMap.

@Centril
Copy link
Contributor

Centril commented Mar 6, 2019

@jeffparsons These days we would welcome a PR against https://github.com/rust-lang/rust/ to unstably implement this in the standard library. An RFC would likely be overkill. If you decide to write up such a PR, please cc this issue. :)

@Centril Centril added the A-collections Proposals about collection APIs label Mar 6, 2019
@jeffparsons
Copy link
Contributor

After familiarizing myself with the BTreeMap source, I think the more valuable thing to implement first would be a cursor API for BTreeMap (and BTreeSet), upon which this and other convenience functions could be easily implemented. I made a very token start on this (it's serious cargo cult stuff at this point) but quickly became frustrated by variants of rust-lang/rust#58633 and put it aside for later.

So... at this point, the things on my mind that more experienced Rust hackers might be able to help answer are:

  • What's the most practical way of working on collection types like BTreeMap? Is there a de facto standard workflow that avoids dealing with the whole compiler build system — even if it is, e.g., copying the whole module out of liballoc into a standalone crate for development? (At the moment if I find a spare half hour in an evening to look at this then I spend most of that time struggling with the build system, which is pretty discouraging.)

  • Is there enough appetite for a general cursor API that it would make sense to build that as a public API now and have that and the convenience functions (retain, range_retain), behind separate feature flags? Or would it be better to wait for the dust to settle around LinkedList cursors (Tracking issue for LinkedList cursors rust#58533) before mooting an equivalent API for BTreeMap, and treat it as an internal implementation detail for now?

@Centril
Copy link
Contributor

Centril commented Mar 12, 2019

@jeffparsons I typically spam ./x.py -i check until things type check and then I ./x.py test --stage 1 src/libstd for standard library changes. See https://rust-lang.github.io/rustc-guide/how-to-build-and-run.html#running-xpy-and-building-a-stage1-compiler for more info.

@mbrubeck
Copy link
Contributor

mbrubeck commented Sep 8, 2020

There was some incomplete work on BTreeMap/BTreeSet::retain at rust-lang/rust#66747.

Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Nov 13, 2020
Implement BTreeMap::retain and BTreeSet::retain

Adds new methods `BTreeMap::retain` and `BTreeSet::retain`.  These are implemented on top of `drain_filter` (rust-lang#70530).

The API of these methods is identical to `HashMap::retain` and `HashSet::retain`, which were implemented in rust-lang#39560 and stabilized in rust-lang#36648.  The docs and tests are also copied from HashMap/HashSet.

The new methods are unstable, behind the `btree_retain` feature gate, with tracking issue rust-lang#79025.  See also rust-lang/rfcs#1338.
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Nov 13, 2020
Implement BTreeMap::retain and BTreeSet::retain

Adds new methods `BTreeMap::retain` and `BTreeSet::retain`.  These are implemented on top of `drain_filter` (rust-lang#70530).

The API of these methods is identical to `HashMap::retain` and `HashSet::retain`, which were implemented in rust-lang#39560 and stabilized in rust-lang#36648.  The docs and tests are also copied from HashMap/HashSet.

The new methods are unstable, behind the `btree_retain` feature gate, with tracking issue rust-lang#79025.  See also rust-lang/rfcs#1338.
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Nov 14, 2020
Implement BTreeMap::retain and BTreeSet::retain

Adds new methods `BTreeMap::retain` and `BTreeSet::retain`.  These are implemented on top of `drain_filter` (rust-lang#70530).

The API of these methods is identical to `HashMap::retain` and `HashSet::retain`, which were implemented in rust-lang#39560 and stabilized in rust-lang#36648.  The docs and tests are also copied from HashMap/HashSet.

The new methods are unstable, behind the `btree_retain` feature gate, with tracking issue rust-lang#79025.  See also rust-lang/rfcs#1338.
@mbrubeck
Copy link
Contributor

BTreeMap::retain has been stabilized for Rust 1.53.0 (scheduled for release in June 2021).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-collections Proposals about collection APIs T-libs-api Relevant to the library API team, which will review and decide on the RFC.
Projects
None yet
Development

No branches or pull requests

6 participants