Skip to content

Commit 7892fe3

Browse files
committed
feat(plenary): rename Deque to Dequeue, simplify
1 parent e4dd966 commit 7892fe3

2 files changed

Lines changed: 16 additions & 20 deletions

File tree

lua/neoplen/async/control.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
local a = require "neoplen.async.async"
2-
local Deque = require("neoplen.async.structs").Deque
2+
local Dequeue = require "neoplen.async.dequeue"
33

44
local M = {}
55

@@ -194,7 +194,7 @@ end
194194
---@return table
195195
---@return table
196196
M.channel.mpsc = function()
197-
local deque = Deque.new()
197+
local deque = Dequeue.new()
198198
local condvar = Condvar.new()
199199

200200
local Sender = {}
Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,35 @@
1-
local M = {}
2-
3-
local Deque = {}
4-
Deque.__index = Deque
1+
local Dequeue = {}
2+
Dequeue.__index = Dequeue
53

64
---@class Deque
75
---A double ended queue
86
---
97
---@return Deque
10-
function Deque.new()
8+
function Dequeue.new()
119
-- the indexes are created with an offset so that the indices are consequtive
1210
-- otherwise, when both pushleft and pushright are used, the indices will have a 1 length hole in the middle
13-
return setmetatable({ first = 0, last = -1 }, Deque)
11+
return setmetatable({ first = 0, last = -1 }, Dequeue)
1412
end
1513

1614
---push to the left of the deque
1715
---@param value any
18-
function Deque:pushleft(value)
16+
function Dequeue:pushleft(value)
1917
local first = self.first - 1
2018
self.first = first
2119
self[first] = value
2220
end
2321

2422
---push to the right of the deque
2523
---@param value any
26-
function Deque:pushright(value)
24+
function Dequeue:pushright(value)
2725
local last = self.last + 1
2826
self.last = last
2927
self[last] = value
3028
end
3129

3230
---pop from the left of the deque
3331
---@return any
34-
function Deque:popleft()
32+
function Dequeue:popleft()
3533
local first = self.first
3634
if first > self.last then
3735
return nil
@@ -44,7 +42,7 @@ end
4442

4543
---pops from the right of the deque
4644
---@return any
47-
function Deque:popright()
45+
function Dequeue:popright()
4846
local last = self.last
4947
if self.first > last then
5048
return nil
@@ -57,19 +55,19 @@ end
5755

5856
---checks if the deque is empty
5957
---@return boolean
60-
function Deque:is_empty()
58+
function Dequeue:is_empty()
6159
return self:len() == 0
6260
end
6361

6462
---returns the number of elements of the deque
6563
---@return number
66-
function Deque:len()
64+
function Dequeue:len()
6765
return self.last - self.first + 1
6866
end
6967

7068
---returns and iterator of the indices and values starting from the left
7169
---@return function
72-
function Deque:ipairs_left()
70+
function Dequeue:ipairs_left()
7371
local i = self.first
7472

7573
return function()
@@ -86,7 +84,7 @@ end
8684

8785
---returns and iterator of the indices and values starting from the right
8886
---@return function
89-
function Deque:ipairs_right()
87+
function Dequeue:ipairs_right()
9088
local i = self.last
9189

9290
return function()
@@ -103,14 +101,12 @@ end
103101

104102
---removes all values from the deque
105103
---@return nil
106-
function Deque:clear()
104+
function Dequeue:clear()
107105
for i, _ in self:ipairs_left() do
108106
self[i] = nil
109107
end
110108
self.first = 0
111109
self.last = -1
112110
end
113111

114-
M.Deque = Deque
115-
116-
return M
112+
return Dequeue

0 commit comments

Comments
 (0)