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

Add BTreeSet entry APIs to match HashSet #133548

Merged
merged 3 commits into from
Nov 30, 2024

Conversation

cuviper
Copy link
Member

@cuviper cuviper commented Nov 27, 2024

The following methods are added, along with the corresponding Entry implementation.

impl<T, A: Allocator + Clone> BTreeSet<T, A> {
    pub fn get_or_insert(&mut self, value: T) -> &T
    where
        T: Ord,
    {...}
    pub fn get_or_insert_with<Q: ?Sized, F>(&mut self, value: &Q, f: F) -> &T
    where
        T: Borrow<Q> + Ord,
        Q: Ord,
        F: FnOnce(&Q) -> T,
    {...}

    pub fn entry(&mut self, value: T) -> Entry<'_, T, A>
    where
        T: Ord,
    {...}
}

Tracking issue #133549
Closes rust-lang/rfcs#1490

* `fn get_or_insert(&mut self, value: T) -> &T`
* `fn get_or_insert_with<Q: ?Sized, F>(&mut self, value: &Q, f: F) -> &T`
* `fn entry(&mut self, value: T) -> Entry<'_, T, A>` (+ `Entry` APIs)
@rustbot
Copy link
Collaborator

rustbot commented Nov 27, 2024

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Nov 27, 2024
@rust-log-analyzer

This comment has been minimized.

@Mark-Simulacrum
Copy link
Member

@bors r+

Given precedent on HashSet, I'm going to go ahead and approve even without an explicit ACP. This is all unstable anyway.

@bors
Copy link
Contributor

bors commented Nov 29, 2024

📌 Commit 21b1ab1 has been approved by Mark-Simulacrum

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 29, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 30, 2024
Rollup of 6 pull requests

Successful merges:

 - rust-lang#131551 (Support input/output in vector registers of PowerPC inline assembly)
 - rust-lang#132515 (Fix and undeprecate home_dir())
 - rust-lang#132721 (CI: split x86_64-mingw job)
 - rust-lang#133106 (changes old intrinsic declaration to new declaration)
 - rust-lang#133496 (thread::available_parallelism for wasm32-wasip1-threads)
 - rust-lang#133548 (Add `BTreeSet` entry APIs to match `HashSet`)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 30, 2024
Rollup of 6 pull requests

Successful merges:

 - rust-lang#131551 (Support input/output in vector registers of PowerPC inline assembly)
 - rust-lang#132515 (Fix and undeprecate home_dir())
 - rust-lang#132721 (CI: split x86_64-mingw job)
 - rust-lang#133106 (changes old intrinsic declaration to new declaration)
 - rust-lang#133496 (thread::available_parallelism for wasm32-wasip1-threads)
 - rust-lang#133548 (Add `BTreeSet` entry APIs to match `HashSet`)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 132fcd8 into rust-lang:master Nov 30, 2024
6 checks passed
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Nov 30, 2024
Rollup merge of rust-lang#133548 - cuviper:btreeset-entry-api, r=Mark-Simulacrum

Add `BTreeSet` entry APIs to match `HashSet`

The following methods are added, along with the corresponding `Entry` implementation.

```rust
impl<T, A: Allocator + Clone> BTreeSet<T, A> {
    pub fn get_or_insert(&mut self, value: T) -> &T
    where
        T: Ord,
    {...}
    pub fn get_or_insert_with<Q: ?Sized, F>(&mut self, value: &Q, f: F) -> &T
    where
        T: Borrow<Q> + Ord,
        Q: Ord,
        F: FnOnce(&Q) -> T,
    {...}

    pub fn entry(&mut self, value: T) -> Entry<'_, T, A>
    where
        T: Ord,
    {...}
}
```

Tracking issue rust-lang#133549
Closes rust-lang/rfcs#1490
@rustbot rustbot added this to the 1.85.0 milestone Nov 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Entry API equivalent for Sets
5 participants