|
79 | 79 | //! see each type's documentation, and note that the names of actual methods may
|
80 | 80 | //! differ from the tables below on certain collections.
|
81 | 81 | //!
|
82 |
| -//! Throughout the documentation, we will adhere to the following conventions for |
83 |
| -//! operation notation: |
| 82 | +//! Throughout the documentation, we will adhere to the following conventions |
| 83 | +//! for operation notation: |
84 | 84 | //!
|
85 | 85 | //! * The collection's size is denoted by `n`.
|
86 |
| -//! * If a second collection is involved, it's size is denoted by `m`. |
| 86 | +//! * If a second collection is involved, its size is denoted by `m`. |
87 | 87 | //! * Item indices are denoted by `i`.
|
88 | 88 | //! * Operations which have an *amortized* cost are suffixed with a `*`.
|
89 | 89 | //! * Operations with an *expected* cost are suffixed with a `~`.
|
|
94 | 94 | //! *Amortized* costs are calculated to account for the time cost of such resize
|
95 | 95 | //! operations *over a sufficiently large series of operations*. An individual
|
96 | 96 | //! operation may be slower or faster due to the sporadic nature of collection
|
97 |
| -//! resizing, however the average cost per operation will eventually equal the |
98 |
| -//! amortized cost. |
| 97 | +//! resizing, however the average cost per operation will approach the amortized |
| 98 | +//! cost. |
99 | 99 | //!
|
100 | 100 | //! Rust's collections never automatically shrink, so removal operations aren't
|
101 | 101 | //! amortized.
|
102 | 102 | //!
|
103 |
| -//! [`HashMap`] uses *expected* costs to denote that it is theoretically possible, |
104 |
| -//! though very unlikely, for [`HashMap`] to experience worse performance than |
105 |
| -//! the expected cost. This is due to the probablilistic nature of hashing - |
106 |
| -//! i.e. it is possible to generate a duplicate hash given some input key that |
107 |
| -//! requires extra computation to correct, but exceptionally unlikely. |
| 103 | +//! [`HashMap`] uses *expected* costs. It is theoretically possible, though very |
| 104 | +//! unlikely, for [`HashMap`] to experience significantly worse performance than |
| 105 | +//! the expected cost. This is due to the probabilistic nature of hashing - i.e. |
| 106 | +//! it is possible to generate a duplicate hash given some input key that will |
| 107 | +//! requires extra computation to correct. |
108 | 108 | //!
|
109 |
| -//! ## Cost of Sequence Operations |
| 109 | +//! ## Cost of Collection Operations |
110 | 110 | //!
|
111 |
| -//! | | get(i) | insert(i) | remove(i) | append(Vec(m)) | split_off(i) | |
112 |
| -//! |----------------|------------------------|-------------------------|------------------------|-------------------|------------------------| |
113 |
| -//! | [`Vec`] | *O*(1) | *O*(*n*-*i*)* | *O*(*n*-*i*) | *O*(*m*)* | *O*(*n*-*i*) | |
114 |
| -//! | [`VecDeque`] | *O*(1) | *O*(min(*i*, *n*-*i*))* | *O*(min(*i*, *n*-*i*)) | *O*(*m*)* | *O*(min(*i*, *n*-*i*)) | |
115 |
| -//! | [`LinkedList`] | *O*(min(*i*, *n*-*i*)) | *O*(min(*i*, *n*-*i*)) | *O*(min(*i*, *n*-*i*)) | *O*(1) | *O*(min(*i*, *n*-*i*)) | |
116 | 111 | //!
|
117 |
| -//! Note that where ties occur, [`Vec`] is generally going to be faster than [`VecDeque`], and |
118 |
| -//! [`VecDeque`] is generally going to be faster than [`LinkedList`]. |
| 112 | +//! | | get(i) | insert(i) | remove(i) | append(Vec(m)) | split_off(i) | range | append | |
| 113 | +//! |----------------|------------------------|-------------------------|------------------------|-------------------|------------------------|-----------------|--------------| |
| 114 | +//! | [`Vec`] | *O*(1) | *O*(*n*-*i*)* | *O*(*n*-*i*) | *O*(*m*)* | *O*(*n*-*i*) | N/A | N/A | |
| 115 | +//! | [`VecDeque`] | *O*(1) | *O*(min(*i*, *n*-*i*))* | *O*(min(*i*, *n*-*i*)) | *O*(*m*)* | *O*(min(*i*, *n*-*i*)) | N/A | N/A | |
| 116 | +//! | [`LinkedList`] | *O*(min(*i*, *n*-*i*)) | *O*(min(*i*, *n*-*i*)) | *O*(min(*i*, *n*-*i*)) | *O*(1) | *O*(min(*i*, *n*-*i*)) | N/A | N/A | |
| 117 | +//! | [`HashMap`] | *O*(1)~ | *O*(1)~* | *O*(1)~ | N/A | N/A | N/A | N/A | |
| 118 | +//! | [`BTreeMap`] | *O*(log(*n*)) | *O*(log(*n*)) | *O*(log(*n*)) | N/A | N/A | *O*(log(*n*)) | *O*(*n*+*m*) | |
119 | 119 | //!
|
120 |
| -//! ## Cost of Map Operations |
| 120 | +//! Note that where ties occur, [`Vec`] is generally going to be faster than |
| 121 | +//! [`VecDeque`], and [`VecDeque`] is generally going to be faster than |
| 122 | +//! [`LinkedList`]. |
121 | 123 | //!
|
122 | 124 | //! For Sets, all operations have the cost of the equivalent Map operation.
|
123 | 125 | //!
|
124 |
| -//! | | get | insert | remove | range | append | |
125 |
| -//! |--------------|---------------|---------------|---------------|---------------|--------------| |
126 |
| -//! | [`HashMap`] | *O*(1)~ | *O*(1)~* | *O*(1)~ | N/A | N/A | |
127 |
| -//! | [`BTreeMap`] | *O*(log(*n*)) | *O*(log(*n*)) | *O*(log(*n*)) | *O*(log(*n*)) | *O*(*n*+*m*) | |
128 |
| -//! |
129 | 126 | //! # Correct and Efficient Usage of Collections
|
130 | 127 | //!
|
131 | 128 | //! Of course, knowing which collection is the right one for the job doesn't
|
|
0 commit comments