模块 lib.container.deque
创建一个Deque值(对象)。
支持在队列头部或尾部进行O(1)插入的双端队列。
函数
| Deque:push (value) | 将值推入队列前端 |
| Deque:push_back (value) | 将值推入队列后端 |
| Deque:extend_back (other_deque) | 将另一个Deque的所有值推入此队列的后端 |
| Deque:pop () | 从队列前端弹出值并返回 |
| Deque:pop_back () | 从队列后端弹出值并返回 |
| Deque:find (value, predicate) | 如果找到匹配项,返回队列中的值。 |
| Deque:contains (value, predicate) | 如果给定值在队列中,返回true。 |
| Deque:remove (value, predicate) | 移除队列中值的第一个实例
可选的谓词函数应该接受两个参数,如果参数被认为是匹配的,则返回true。 |
| Deque:count () | 返回队列中元素/值的数量 |
| Deque:clear () | 清除队列中的所有元素 |
| Deque:ipairs () | 返回一个行为类似ipairs的队列迭代器 |
| Deque:to_array () | 返回包含队列元素的列表/数组(这里头部是索引1) |
函数
- Deque:push (value)
-
将值推入队列前端
参数:
- value anything 要插入的值
- Deque:push_back (value)
-
将值推入队列后端
参数:
- value anything 要插入的值
- Deque:extend_back (other_deque)
-
将另一个Deque的所有值推入此队列的后端
参数:
- other_deque Deque 要插入的值
- Deque:pop ()
-
从队列前端弹出值并返回
返回:
-
anything
- Deque:pop_back ()
-
从队列后端弹出值并返回
返回:
-
anything
- Deque:find (value, predicate)
-
如果找到匹配项,返回队列中的值。
可选的谓词函数应该接受两个参数,如果参数被认为是匹配的,则返回true。默认谓词是==。
参数:
- value anything 要在队列中搜索的值
- predicate function 比较函数[可选]
返回:
-
anything
- Deque:contains (value, predicate)
-
如果给定值在队列中,返回true。
可选的谓词函数应该接受两个参数,如果参数被认为是匹配的,则返回true。默认谓词是==。
参数:
- value anything 要在队列中搜索的值
- predicate function 比较函数[可选]
返回:
-
boolean
- Deque:remove (value, predicate)
-
移除队列中值的第一个实例
可选的谓词函数应该接受两个参数,如果参数被认为是匹配的,则返回true。默认谓词是==。
参数:
- value anything 要从队列中移除的值
- predicate function 比较函数[可选]
返回:
-
anything
被移除的值或nil
- Deque:count ()
-
返回队列中元素/值的数量
返回:
-
int
- Deque:clear ()
- 清除队列中的所有元素
- Deque:ipairs ()
-
返回一个行为类似ipairs的队列迭代器
返回:
-
function
- Deque:to_array ()
- 返回包含队列元素的列表/数组(这里头部是索引1)