Commit Graph

736 Commits

Author SHA1 Message Date
Josh Stone 10efaa37de Remove an old comment from HashMap::extend_reserve 2020-05-29 17:05:17 -07:00
Josh Stone 6700e18688 Add Extend::{extend_one,extend_reserve}
This adds new optional methods on `Extend`: `extend_one` add a single
element to the collection, and `extend_reserve` pre-allocates space for
the predicted number of incoming elements. These are used in `Iterator`
for `partition` and `unzip` as they shuffle elements one-at-a-time into
their respective collections.
2020-05-29 17:05:17 -07:00
Mark Rousskov cf5e4a749c Add explicit references to the BuildHasher trait 2020-04-29 11:04:57 -04:00
Philipp Hansch 23b9f46fff More diagnostic items for Clippy usage
This adds a couple of more diagnostic items to be used in Clippy.
I chose these particular ones because they were the types which we seem
to check for the most in Clippy. I'm not sure if the
`cfg_attr(not(test))` is needed, but it was also used for `Vec` and a
few other types.
2020-04-22 07:57:56 +02:00
Ralf Jung 88612e3657 big-O notation: parenthesis, multiplication and backticks 2020-04-15 14:33:45 +02:00
Chai T. Rex db0c39fba5 Change issue number to point to tracking issue 2020-04-11 08:46:12 -04:00
Chai T. Rex 78102377d0 Fixed doc tests for added methods 2020-04-10 13:45:34 -04:00
Chai T. Rex 921579cc3c Add or_insert_with_key to Entry of HashMap/BTreeMap
Going along with or_insert_with, or_insert_with_key provides the
Entry's key to the lambda, avoiding the need to either clone the
key or the need to reimplement this body of this method from
scratch each time.

This is useful when the initial value for a map entry is derived
from the key. For example, the introductory Rust book has an
example Cacher struct that takes an expensive-to-compute lambda and
then can, given an argument to the lambda, produce either the
cached result or execute the lambda.
2020-04-10 12:54:09 -04:00
Linus Färnstrand 68b1af6624 Don't import integer module in libstd 2020-04-06 23:08:46 +02:00
Matthias Krüger 83980aca20 Don't redundantly repeat field names (clippy::redundant_field_names) 2020-03-06 19:42:18 +01:00
Dylan DPC 2a201336ed Rollup merge of #67642 - Mark-Simulacrum:relax-bounds, r=Amanieu
Relax bounds on HashMap/HashSet

These APIs changed from the old bound listed to the new bound (possibly empty):

K: Hash + Eq -> K
* new
* with_capacity

K: Eq + Hash, S: BuildHasher -> K, S
* with_hasher
* with_capacity_and_hasher
* hasher

K: Eq + Hash + Debug -> K: Debug
S: BuildHasher -> S
HashMap as Debug

K: Eq + Hash -> K
S: BuildHasher + Default -> S: Default
HashMap as Default

Resolves #44777.
2020-02-13 02:52:46 +01:00
Josh Stone 4ede63bee1 Add HashSet::get_or_insert_owned 2020-01-08 15:34:06 -08:00
Mark Rousskov 48859db151 Relax bounds on HashSet to match hashbrown
No functional changes are made, and all APIs are moved to strictly less
restrictive bounds.

These APIs changed from the old bound listed to the new bound:

T: Hash + Eq -> T
* new
* with_capacity

T: Eq + Hash, S: BuildHasher -> T
* with_hasher
* with_capacity_and_hasher
* hasher

T: Eq + Hash + Debug -> T: Debug
S: BuildHasher -> S
<HashSet as Debug>

T: Eq + Hash -> T
S: BuildHasher + Default -> S: Default
<HashSet as Default>
2019-12-26 19:24:45 -05:00
Mark Rousskov 3b92689f3d Relax bounds on HashMap to match hashbrown
No functional changes are made, and all APIs are moved to strictly less
restrictive bounds.

These APIs changed from the old bound listed to no trait bounds:

K: Hash + Eq
* new
* with_capacity

K: Eq + Hash, S: BuildHasher
* with_hasher
* with_capacity_and_hasher
* hasher

K: Eq + Hash + Debug -> K: Debug
S: BuildHasher -> S
<HashMap as Debug>

K: Eq + Hash -> K
S: BuildHasher + Default -> S: Default
<HashMap as Default>
2019-12-26 13:55:17 -05:00
Matthew Kraai 21e636f188 Remove redundant link texts 2019-12-26 05:04:46 -08:00
Mark Rousskov a06baa56b9 Format the world 2019-12-22 17:42:47 -05:00
Christoph Schmidler a678628e58 Update HashMap documentation hint of the used 'quadratic probing' and 'SIMD lookup' algorithms 2019-12-09 20:13:42 +01:00
David Tolnay 4436c9d354 Format libstd with rustfmt
This commit applies rustfmt with rust-lang/rust's default settings to
files in src/libstd *that are not involved in any currently open PR* to
minimize merge conflicts. THe list of files involved in open PRs was
determined by querying GitHub's GraphQL API with this script:
https://gist.github.com/dtolnay/aa9c34993dc051a4f344d1b10e4487e8

With the list of files from the script in outstanding_files, the
relevant commands were:

    $ find src/libstd -name '*.rs' \
        | xargs rustfmt --edition=2018 --unstable-features --skip-children
    $ rg libstd outstanding_files | xargs git checkout --

Repeating this process several months apart should get us coverage of
most of the rest of libstd.

To confirm no funny business:

    $ git checkout $THIS_COMMIT^
    $ git show --pretty= --name-only $THIS_COMMIT \
        | xargs rustfmt --edition=2018 --unstable-features --skip-children
    $ git diff $THIS_COMMIT  # there should be no difference
2019-11-29 18:43:27 -08:00
Stein Somers 4decb58a64 introduce benchmarks of HashSet operations 2019-11-14 12:59:35 +01:00
Stepan Koltsov 04a237b9e2 Fix HashSet::union performance
Consider this example: small_set = 0..2, large_set = 0..1000.

To efficiently compute the union of these sets, we should
* take all elements of the larger set
* for each element of the smaller set check it is not in the larger set

This is exactly what this commit does.

This particular optimization was implemented a year ago, but the
author mistaken `<` and `>`.
2019-11-10 23:53:44 +00:00
Tyler Mandry 9175247e72 Rollup merge of #65112 - jack-t:type-parens-lint, r=varkor
Add lint and tests for unnecessary parens around types

This is my first contribution to the Rust project, so I apologize if I'm not doing things the right way.

The PR fixes #64169. It adds a lint and tests for unnecessary parentheses around types. I've run `tidy` and `rustfmt` &mdash; I'm not totally sure it worked right, though &mdash; and I've tried to follow the instructions linked in the readme.

I tried to think through all the variants of `ast::TyKind` to find exceptions to this lint, and I could only find the one mentioned in the original issue, which concerns types with `dyn`. I'm not a Rust expert, thought, so I may well be missing something.

There's also a problem with getting this to build. The new lint catches several things in the, e.g., `core`. Because `x.py` seems to build with an equivalent of `-Werror`, what would have been warnings cause the build to break. I got it to build and the tests to pass with `--warnings warn` on my `x.py build` and `x.py test` commands.
2019-11-01 11:20:07 -07:00
jack-t 08ca2360c4 Add lint for unnecessary parens around types 2019-10-29 18:11:12 +00:00
Tyler Mandry ec1d008f65 Rollup merge of #65048 - Kixunil:patch-1, r=KodrAus
Added doc about behavior of extend on HashMap

It was unclear what the implementation does when it encounters existing keys. This change makes it clear by documenting the trait impl.
2019-10-11 15:09:44 -07:00
Félix Saparelli bdcc21cbc4 Implement (HashMap) Entry::insert as per #60142 2019-10-09 11:00:29 +13:00
Martin Habovštiak 00d9db14f7 Added doc about behavior of extend on HashMap
It was unclear what the implementation does when it encounters existing keys. This change makes it clear by documenting the trait impl.
2019-10-03 10:09:04 +02:00
Lzu Tao 6c1b447f2e Remove unneeded fn main blocks from docs 2019-10-01 11:55:46 +00:00
Lzu Tao c482c84142 Stabilize map_get_key_value feature 2019-09-27 11:21:57 +00:00
Simon Sapin 59a340963f Add the Layout of the failed allocation to TryReserveError::AllocError
… and add a separately-unstable field to force non-exhaustive matching
(`#[non_exhaustive]` is no implemented yet on enum variants)
so that we have the option to later expose the allocator’s error value.

CC https://github.com/rust-lang/wg-allocators/issues/23
2019-08-16 18:08:37 +02:00
Simon Sapin a92c29b238 Update hashbrown to 0.5.0 2019-08-16 18:08:35 +02:00
Simon Sapin 36b18a1901 Rename CollectionAllocError to TryReserveError 2019-08-16 18:08:06 +02:00
Nick Hynes 503cedac0c Test that maplike FromIter satisfies uniqueness 2019-07-16 02:34:00 +00:00
Simon Sapin 7454b29efc HashMap is UnwindSafe
Fixes https://github.com/rust-lang/rust/issues/62301, a regression in 1.36.0 which was caused by hashbrown using `NonZero<T>` where the older hashmap used `Unique<T>`.
2019-07-02 16:01:06 +02:00
Mazdak Farrokhzad a34dae3587 Rollup merge of #60511 - taiki-e:libstd-intra-doc, r=Dylan-DPC
Fix intra-doc link resolution failure on re-exporting libstd

Currently, re-exporting libstd items as below will [occur a lot of failures](https://gist.github.com/taiki-e/e33e0e8631ef47f65a74a3b69f456366).
```rust
pub use std::*;
```

Until the underlying issue (#56922) fixed, we can fix that so they don't propagate to downstream crates.

Related: https://github.com/rust-lang/rust/pull/56941 (That PR fixed failures that occur when re-exporting from libcore to libstd.)

r? @QuietMisdreavus
2019-05-20 23:02:59 +02:00
bors 68fd80fa1e Auto merge of #60899 - cuviper:RawEntryMut-origin-story, r=Centril
doc: correct the origin of RawEntryMut
2019-05-17 07:24:16 +00:00
Josh Stone 4d61fb1ba4 doc: correct the origin of RawEntryMut 2019-05-16 18:15:09 -07:00
Josh Stone 9161a4dbef Comment why get_or_insert returns &T 2019-05-16 16:21:31 -07:00
Josh Stone 5e2c9d38e9 Add a hash_set_entry tracking issue 2019-05-16 15:37:01 -07:00
Josh Stone 5f938342ce Add entry-like methods to HashSet
* `HashSet::get_or_insert`
* `HashSet::get_or_insert_with`

These provide a simplification of the `Entry` API for `HashSet`, with
names chosen to match the similar methods on `Option`.
2019-05-16 15:10:52 -07:00
Taiki Endo ccb9dac5ed Fix intra-doc link resolution failure on re-exporting libstd 2019-05-04 23:48:57 +09:00
varkor aa388f1d11 ignore-tidy-filelength on all files with greater than 3000 lines 2019-04-25 21:39:09 +01:00
Amanieu d'Antras e15bf96cb2 Remove broken tests 2019-04-24 06:54:14 +08:00
Amanieu d'Antras cf46bd5037 Replace the robin-hood hash table with hashbrown 2019-04-24 06:54:14 +08:00
Amanieu d'Antras 556fc40a95 Mark HashSet functions with #[inline] 2019-04-24 06:54:14 +08:00
Amanieu d'Antras a533504ca1 Add try_reserve to HashSet 2019-04-24 06:54:14 +08:00
Amanieu d'Antras 185ed988d2 Remove the Recover trait for HashSet 2019-04-24 06:54:14 +08:00
Marc 64dc041511 Remove collection-specific with_capacity doc from std::collections
Fixes #59931
2019-04-15 20:30:52 +12:00
Stein Somers 5b8bfe0471 improve worst-case performance of HashSet.is_subset 2019-04-03 13:01:01 +02:00
Mazdak Farrokhzad 379c380a60 libstd: deny(elided_lifetimes_in_paths) 2019-03-31 12:56:51 +02:00
kennytm d1744728a0 Rollup merge of #59082 - alexreg:cosmetic-2-doc-comments, r=Centril
A few improvements to comments in user-facing crates

Not too many this time, and all concern comments (almost all doc comments) in user-facing crates (libstd, libcore, liballoc).

r? @steveklabnik
2019-03-16 22:39:56 +08:00
Alexander Regueiro 8629fd3e4e Improvements to comments in libstd, libcore, liballoc. 2019-03-11 02:25:44 +00:00