forked from nvim-lua/plenary.nvim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.lua
More file actions
50 lines (40 loc) · 977 Bytes
/
helpers.lua
File metadata and controls
50 lines (40 loc) · 977 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
local M = {}
VecDeque = {}
VecDeque.__index = VecDeque
function VecDeque.new()
return setmetatable({first = 0, last = -1}, VecDeque)
end
function VecDeque:pushleft(value)
local first = self.first - 1
self.first = first
self[first] = value
end
function VecDeque:pushright(value)
local last = self.last + 1
self.last = last
self[last] = value
end
function VecDeque:popleft()
local first = self.first
if first > self.last then return nil end
local value = self[first]
self[first] = nil -- to allow garbage collection
self.first = first + 1
return value
end
function VecDeque:is_empty()
return self.first > self.last
end
function VecDeque:popright()
local last = self.last
if self.first > last then return nil end
local value = self[last]
self[last] = nil -- to allow garbage collection
self.last = last - 1
return value
end
function VecDeque:len()
return self.last - self.first
end
M.VecDeque = VecDeque
return M