双端队列有下标运算符的原因是什么?
What is the reasoning for a deque to have a subscript operator?
我今天和一个朋友聊天,他提到双端队列元素可以通过下标运算符访问,而其他 "similar" DS,如队列和堆栈则不能。毕竟,deque 不就是双端队列的意思吗?可以随机访问 deque 的事实不会破坏 deque 数据结构的完整性吗?
此外,从性能的角度来看,除非您实际使用双端队列方法(前端和后端函数系列),否则双端队列不会完全使用下标运算符来减少 table 吗?我知道 deque 背后的实现将它分成 chunks/blocks,并且通常需要两个操作才能实际随机访问一个元素,而向量保证在连续的内存中。
谢谢!
Doesn't the fact that deque's can be randomly accessed ruin the very integrity of the deque data structure?
没有。你只是挂在它的名字上。我们确实对 "queue" 有一个明确的定义,所以这可能是一个糟糕的词选择,但数据结构并不是由它的名字定义的。
日期结构是具有一组特定关联操作的数据 (duh)。标准库使用下标运算符定义 deque
。这就是数据结构。我们非常小心地确保操作的各种要求不会发生冲突,因此 deque
作为数据结构的完整性得到了很好的支持。
Also, for a performance standpoint, don't deque's just bring less to the table entirely with the subscript operator unless you're actually utilizing deque methods (the family of front and back functions)? I understand that the implementation behind deque's splits it up into chunks/blocks, and that it generally takes two operations to actually randomly access a element, whereas vectors are guaranteed to be in contiguous memory.
deque与vector相比还有一个优势。如果连续内存很大,超过 OS 可以分配的内存,则可能 运行 内存不足。因为双端队列是分页内存,一个好的实现可以降低对 OS 的要求,因为内存要求是不连续的。
我今天和一个朋友聊天,他提到双端队列元素可以通过下标运算符访问,而其他 "similar" DS,如队列和堆栈则不能。毕竟,deque 不就是双端队列的意思吗?可以随机访问 deque 的事实不会破坏 deque 数据结构的完整性吗?
此外,从性能的角度来看,除非您实际使用双端队列方法(前端和后端函数系列),否则双端队列不会完全使用下标运算符来减少 table 吗?我知道 deque 背后的实现将它分成 chunks/blocks,并且通常需要两个操作才能实际随机访问一个元素,而向量保证在连续的内存中。
谢谢!
Doesn't the fact that deque's can be randomly accessed ruin the very integrity of the deque data structure?
没有。你只是挂在它的名字上。我们确实对 "queue" 有一个明确的定义,所以这可能是一个糟糕的词选择,但数据结构并不是由它的名字定义的。
日期结构是具有一组特定关联操作的数据 (duh)。标准库使用下标运算符定义 deque
。这就是数据结构。我们非常小心地确保操作的各种要求不会发生冲突,因此 deque
作为数据结构的完整性得到了很好的支持。
Also, for a performance standpoint, don't deque's just bring less to the table entirely with the subscript operator unless you're actually utilizing deque methods (the family of front and back functions)? I understand that the implementation behind deque's splits it up into chunks/blocks, and that it generally takes two operations to actually randomly access a element, whereas vectors are guaranteed to be in contiguous memory.
deque与vector相比还有一个优势。如果连续内存很大,超过 OS 可以分配的内存,则可能 运行 内存不足。因为双端队列是分页内存,一个好的实现可以降低对 OS 的要求,因为内存要求是不连续的。