rust/library/alloc/src/collections
bors 69df0f2c2f Auto merge of #102991 - Sp00ph:master, r=scottmcm
Update VecDeque implementation to use head+len instead of head+tail

(See #99805)

This changes `alloc::collections::VecDeque`'s internal representation from using head and tail indices to using a head index and a length field. It has a few advantages over the current design:
* It allows the buffer to be of length 0, which means the `VecDeque::new` new longer has to allocate and could be changed to a `const fn`
* It allows the `VecDeque` to fill the buffer completely, unlike the old implementation, which always had to leave a free space
* It removes the restriction for the size to be a power of two, allowing it to properly `shrink_to_fit`, unlike the old `VecDeque`
* The above points also combine to allow the `Vec<T> -> VecDeque<T>` conversion to be very cheap and guaranteed O(1). I mention this in the `From<Vec<T>>` impl, but it's not a strong guarantee just yet, as that would likely need some form of API change proposal.

All the tests seem to pass for the new `VecDeque`, with some slight adjustments.

r? `@scottmcm`
2022-11-28 10:39:47 +00:00
..
binary_heap Use Box::new() instead of box syntax in alloc tests 2022-05-29 00:41:14 +02:00
btree replace unusual grammar 2022-11-20 17:28:34 +02:00
linked_list Use Box::new() instead of box syntax in alloc tests 2022-05-29 00:41:14 +02:00
vec_deque Add second test case in make_contiguous_head_to_end 2022-11-26 23:08:57 +01:00
binary_heap.rs Guarantee try_reserve preserves the contents on error 2022-08-10 01:51:38 +09:00
linked_list.rs more dupe word typos 2022-10-14 12:57:56 +08:00
mod.rs Modify comment syntax error 2022-11-07 14:33:33 +08:00