Skip to content

Commit 9ec7c65

Browse files
Add missing urls in collections module
1 parent eb38d42 commit 9ec7c65

File tree

1 file changed

+65
-55
lines changed

1 file changed

+65
-55
lines changed

src/libstd/collections/mod.rs

Lines changed: 65 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
//! standard implementations, it should be possible for two libraries to
1616
//! communicate without significant data conversion.
1717
//!
18-
//! To get this out of the way: you should probably just use `Vec` or `HashMap`.
18+
//! To get this out of the way: you should probably just use [`Vec`] or [`HashMap`].
1919
//! These two collections cover most use cases for generic data storage and
2020
//! processing. They are exceptionally good at doing what they do. All the other
2121
//! collections in the standard library have specific use cases where they are
@@ -25,10 +25,10 @@
2525
//!
2626
//! Rust's collections can be grouped into four major categories:
2727
//!
28-
//! * Sequences: `Vec`, `VecDeque`, `LinkedList`
29-
//! * Maps: `HashMap`, `BTreeMap`
30-
//! * Sets: `HashSet`, `BTreeSet`
31-
//! * Misc: `BinaryHeap`
28+
//! * Sequences: [`Vec`], [`VecDeque`], [`LinkedList`]
29+
//! * Maps: [`HashMap`], [`BTreeMap`]
30+
//! * Sets: [`HashSet`], [`BTreeSet`]
31+
//! * Misc: [`BinaryHeap`]
3232
//!
3333
//! # When Should You Use Which Collection?
3434
//!
@@ -46,13 +46,13 @@
4646
//! * You want a heap-allocated array.
4747
//!
4848
//! ### Use a `VecDeque` when:
49-
//! * You want a `Vec` that supports efficient insertion at both ends of the
49+
//! * You want a [`Vec`] that supports efficient insertion at both ends of the
5050
//! sequence.
5151
//! * You want a queue.
5252
//! * You want a double-ended queue (deque).
5353
//!
5454
//! ### Use a `LinkedList` when:
55-
//! * You want a `Vec` or `VecDeque` of unknown size, and can't tolerate
55+
//! * You want a [`Vec`] or [`VecDeque`] of unknown size, and can't tolerate
5656
//! amortization.
5757
//! * You want to efficiently split and append lists.
5858
//! * You are *absolutely* certain you *really*, *truly*, want a doubly linked
@@ -92,38 +92,38 @@
9292
//! Throughout the documentation, we will follow a few conventions. For all
9393
//! operations, the collection's size is denoted by n. If another collection is
9494
//! involved in the operation, it contains m elements. Operations which have an
95-
//! *amortized* cost are suffixed with a `*`. Operations with an *expected*
95+
//! *amortized* cost are suffixed with a `*`. Operations with an *expected*
9696
//! cost are suffixed with a `~`.
9797
//!
9898
//! All amortized costs are for the potential need to resize when capacity is
99-
//! exhausted. If a resize occurs it will take O(n) time. Our collections never
99+
//! exhausted. If a resize occurs it will take O(n) time. Our collections never
100100
//! automatically shrink, so removal operations aren't amortized. Over a
101101
//! sufficiently large series of operations, the average cost per operation will
102102
//! deterministically equal the given cost.
103103
//!
104-
//! Only HashMap has expected costs, due to the probabilistic nature of hashing.
105-
//! It is theoretically possible, though very unlikely, for HashMap to
104+
//! Only [`HashMap`] has expected costs, due to the probabilistic nature of hashing.
105+
//! It is theoretically possible, though very unlikely, for [`HashMap`] to
106106
//! experience worse performance.
107107
//!
108108
//! ## Sequences
109109
//!
110-
//! | | get(i) | insert(i) | remove(i) | append | split_off(i) |
111-
//! |--------------|----------------|-----------------|----------------|--------|----------------|
112-
//! | Vec | O(1) | O(n-i)* | O(n-i) | O(m)* | O(n-i) |
113-
//! | VecDeque | O(1) | O(min(i, n-i))* | O(min(i, n-i)) | O(m)* | O(min(i, n-i)) |
114-
//! | LinkedList | O(min(i, n-i)) | O(min(i, n-i)) | O(min(i, n-i)) | O(1) | O(min(i, n-i)) |
110+
//! | | get(i) | insert(i) | remove(i) | append | split_off(i) |
111+
//! |----------------|----------------|-----------------|----------------|--------|----------------|
112+
//! | [`Vec`] | O(1) | O(n-i)* | O(n-i) | O(m)* | O(n-i) |
113+
//! | [`VecDeque`] | O(1) | O(min(i, n-i))* | O(min(i, n-i)) | O(m)* | O(min(i, n-i)) |
114+
//! | [`LinkedList`] | O(min(i, n-i)) | O(min(i, n-i)) | O(min(i, n-i)) | O(1) | O(min(i, n-i)) |
115115
//!
116-
//! Note that where ties occur, Vec is generally going to be faster than VecDeque, and VecDeque
117-
//! is generally going to be faster than LinkedList.
116+
//! Note that where ties occur, [`Vec`] is generally going to be faster than [`VecDeque`], and
117+
//! [`VecDeque`] is generally going to be faster than [`LinkedList`].
118118
//!
119119
//! ## Maps
120120
//!
121121
//! For Sets, all operations have the cost of the equivalent Map operation.
122122
//!
123-
//! | | get | insert | remove | predecessor | append |
124-
//! |----------|-----------|----------|----------|-------------|--------|
125-
//! | HashMap | O(1)~ | O(1)~* | O(1)~ | N/A | N/A |
126-
//! | BTreeMap | O(log n) | O(log n) | O(log n) | O(log n) | O(n+m) |
123+
//! | | get | insert | remove | predecessor | append |
124+
//! |--------------|-----------|----------|----------|-------------|--------|
125+
//! | [`HashMap`] | O(1)~ | O(1)~* | O(1)~ | N/A | N/A |
126+
//! | [`BTreeMap`] | O(log n) | O(log n) | O(log n) | O(log n) | O(n+m) |
127127
//!
128128
//! # Correct and Efficient Usage of Collections
129129
//!
@@ -136,7 +136,7 @@
136136
//! ## Capacity Management
137137
//!
138138
//! Many collections provide several constructors and methods that refer to
139-
//! "capacity". These collections are generally built on top of an array.
139+
//! "capacity". These collections are generally built on top of an array.
140140
//! Optimally, this array would be exactly the right size to fit only the
141141
//! elements stored in the collection, but for the collection to do this would
142142
//! be very inefficient. If the backing array was exactly the right size at all
@@ -157,29 +157,29 @@
157157
//! information to do this itself. Therefore, it is up to us programmers to give
158158
//! it hints.
159159
//!
160-
//! Any `with_capacity` constructor will instruct the collection to allocate
160+
//! Any `with_capacity()` constructor will instruct the collection to allocate
161161
//! enough space for the specified number of elements. Ideally this will be for
162162
//! exactly that many elements, but some implementation details may prevent
163-
//! this. `Vec` and `VecDeque` can be relied on to allocate exactly the
164-
//! requested amount, though. Use `with_capacity` when you know exactly how many
163+
//! this. [`Vec`] and [`VecDeque`] can be relied on to allocate exactly the
164+
//! requested amount, though. Use `with_capacity()` when you know exactly how many
165165
//! elements will be inserted, or at least have a reasonable upper-bound on that
166166
//! number.
167167
//!
168-
//! When anticipating a large influx of elements, the `reserve` family of
168+
//! When anticipating a large influx of elements, the `reserve()` family of
169169
//! methods can be used to hint to the collection how much room it should make
170-
//! for the coming items. As with `with_capacity`, the precise behavior of
170+
//! for the coming items. As with `with_capacity()`, the precise behavior of
171171
//! these methods will be specific to the collection of interest.
172172
//!
173173
//! For optimal performance, collections will generally avoid shrinking
174-
//! themselves. If you believe that a collection will not soon contain any more
175-
//! elements, or just really need the memory, the `shrink_to_fit` method prompts
174+
//! themselves. If you believe that a collection will not soon contain any more
175+
//! elements, or just really need the memory, the `shrink_to_fit()` method prompts
176176
//! the collection to shrink the backing array to the minimum size capable of
177177
//! holding its elements.
178178
//!
179179
//! Finally, if ever you're interested in what the actual capacity of the
180-
//! collection is, most collections provide a `capacity` method to query this
181-
//! information on demand. This can be useful for debugging purposes, or for
182-
//! use with the `reserve` methods.
180+
//! collection is, most collections provide a `capacity()` method to query this
181+
//! information on demand. This can be useful for debugging purposes, or for
182+
//! use with the `reserve()` methods.
183183
//!
184184
//! ## Iterators
185185
//!
@@ -194,15 +194,15 @@
194194
//!
195195
//! All of the standard collections provide several iterators for performing
196196
//! bulk manipulation of their contents. The three primary iterators almost
197-
//! every collection should provide are `iter`, `iter_mut`, and `into_iter`.
197+
//! every collection should provide are `iter()`, `iter_mut()`, and `into_iter()`.
198198
//! Some of these are not provided on collections where it would be unsound or
199199
//! unreasonable to provide them.
200200
//!
201-
//! `iter` provides an iterator of immutable references to all the contents of a
202-
//! collection in the most "natural" order. For sequence collections like `Vec`,
201+
//! `iter()` provides an iterator of immutable references to all the contents of a
202+
//! collection in the most "natural" order. For sequence collections like [`Vec`],
203203
//! this means the items will be yielded in increasing order of index starting
204-
//! at 0. For ordered collections like `BTreeMap`, this means that the items
205-
//! will be yielded in sorted order. For unordered collections like `HashMap`,
204+
//! at 0. For ordered collections like [`BTreeMap`], this means that the items
205+
//! will be yielded in sorted order. For unordered collections like [`HashMap`],
206206
//! the items will be yielded in whatever order the internal representation made
207207
//! most convenient. This is great for reading through all the contents of the
208208
//! collection.
@@ -214,8 +214,8 @@
214214
//! }
215215
//! ```
216216
//!
217-
//! `iter_mut` provides an iterator of *mutable* references in the same order as
218-
//! `iter`. This is great for mutating all the contents of the collection.
217+
//! `iter_mut()` provides an iterator of *mutable* references in the same order as
218+
//! `iter()`. This is great for mutating all the contents of the collection.
219219
//!
220220
//! ```
221221
//! let mut vec = vec![1, 2, 3, 4];
@@ -224,12 +224,12 @@
224224
//! }
225225
//! ```
226226
//!
227-
//! `into_iter` transforms the actual collection into an iterator over its
227+
//! `into_iter()` transforms the actual collection into an iterator over its
228228
//! contents by-value. This is great when the collection itself is no longer
229-
//! needed, and the values are needed elsewhere. Using `extend` with `into_iter`
229+
//! needed, and the values are needed elsewhere. Using `extend()` with `into_iter()`
230230
//! is the main way that contents of one collection are moved into another.
231-
//! `extend` automatically calls `into_iter`, and takes any `T: IntoIterator`.
232-
//! Calling `collect` on an iterator itself is also a great way to convert one
231+
//! `extend()` automatically calls `into_iter()`, and takes any `T: `[`IntoIterator`].
232+
//! Calling `collect()` on an iterator itself is also a great way to convert one
233233
//! collection into another. Both of these methods should internally use the
234234
//! capacity management tools discussed in the previous section to do this as
235235
//! efficiently as possible.
@@ -248,9 +248,9 @@
248248
//! ```
249249
//!
250250
//! Iterators also provide a series of *adapter* methods for performing common
251-
//! threads to sequences. Among the adapters are functional favorites like `map`,
252-
//! `fold`, `skip`, and `take`. Of particular interest to collections is the
253-
//! `rev` adapter, that reverses any iterator that supports this operation. Most
251+
//! threads to sequences. Among the adapters are functional favorites like `map()`,
252+
//! `fold()`, `skip()` and `take()`. Of particular interest to collections is the
253+
//! `rev()` adapter, that reverses any iterator that supports this operation. Most
254254
//! collections provide reversible iterators as the way to iterate over them in
255255
//! reverse order.
256256
//!
@@ -263,42 +263,42 @@
263263
//!
264264
//! Several other collection methods also return iterators to yield a sequence
265265
//! of results but avoid allocating an entire collection to store the result in.
266-
//! This provides maximum flexibility as `collect` or `extend` can be called to
266+
//! This provides maximum flexibility as `collect()` or `extend()` can be called to
267267
//! "pipe" the sequence into any collection if desired. Otherwise, the sequence
268268
//! can be looped over with a `for` loop. The iterator can also be discarded
269269
//! after partial use, preventing the computation of the unused items.
270270
//!
271271
//! ## Entries
272272
//!
273-
//! The `entry` API is intended to provide an efficient mechanism for
273+
//! The `entry()` API is intended to provide an efficient mechanism for
274274
//! manipulating the contents of a map conditionally on the presence of a key or
275275
//! not. The primary motivating use case for this is to provide efficient
276276
//! accumulator maps. For instance, if one wishes to maintain a count of the
277277
//! number of times each key has been seen, they will have to perform some
278278
//! conditional logic on whether this is the first time the key has been seen or
279-
//! not. Normally, this would require a `find` followed by an `insert`,
279+
//! not. Normally, this would require a `find()` followed by an `insert()`,
280280
//! effectively duplicating the search effort on each insertion.
281281
//!
282282
//! When a user calls `map.entry(&key)`, the map will search for the key and
283283
//! then yield a variant of the `Entry` enum.
284284
//!
285285
//! If a `Vacant(entry)` is yielded, then the key *was not* found. In this case
286-
//! the only valid operation is to `insert` a value into the entry. When this is
286+
//! the only valid operation is to `insert()` a value into the entry. When this is
287287
//! done, the vacant entry is consumed and converted into a mutable reference to
288288
//! the value that was inserted. This allows for further manipulation of the
289289
//! value beyond the lifetime of the search itself. This is useful if complex
290290
//! logic needs to be performed on the value regardless of whether the value was
291291
//! just inserted.
292292
//!
293293
//! If an `Occupied(entry)` is yielded, then the key *was* found. In this case,
294-
//! the user has several options: they can `get`, `insert`, or `remove` the
294+
//! the user has several options: they can `get()`, `insert()` or `remove()` the
295295
//! value of the occupied entry. Additionally, they can convert the occupied
296296
//! entry into a mutable reference to its value, providing symmetry to the
297-
//! vacant `insert` case.
297+
//! vacant `insert()` case.
298298
//!
299299
//! ### Examples
300300
//!
301-
//! Here are the two primary ways in which `entry` is used. First, a simple
301+
//! Here are the two primary ways in which `entry()` is used. First, a simple
302302
//! example where the logic performed on the values is trivial.
303303
//!
304304
//! #### Counting the number of times each character in a string occurs
@@ -322,7 +322,7 @@
322322
//! ```
323323
//!
324324
//! When the logic to be performed on the value is more complex, we may simply
325-
//! use the `entry` API to ensure that the value is initialized, and perform the
325+
//! use the `entry()` API to ensure that the value is initialized and perform the
326326
//! logic afterwards.
327327
//!
328328
//! #### Tracking the inebriation of customers at a bar
@@ -406,6 +406,16 @@
406406
//! // ...but the key hasn't changed. b is still "baz", not "xyz".
407407
//! assert_eq!(map.keys().next().unwrap().b, "baz");
408408
//! ```
409+
//!
410+
//! [`Vec`]: ../../std/vec/struct.Vec.html
411+
//! [`HashMap`]: ../../std/collections/struct.HashMap.html
412+
//! [`VecDeque`]: ../../std/collections/struct.VecDeque.html
413+
//! [`LinkedList`]: ../../std/collections/struct.LinkedList.html
414+
//! [`BTreeMap`]: ../../std/collections/struct.BTreeMap.html
415+
//! [`HashSet`]: ../../std/collections/struct.HashSet.html
416+
//! [`BTreeSet`]: ../../std/collections/struct.BTreeSet.html
417+
//! [`BinaryHeap`]: ../../std/collections/struct.BinaryHeap.html
418+
//! [`IntoIterator`]: ../../std/iter/trait.IntoIterator.html
409419
410420
#![stable(feature = "rust1", since = "1.0.0")]
411421

0 commit comments

Comments
 (0)