-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathQIT.lua
65 lines (55 loc) · 1.47 KB
/
QIT.lua
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
---@class QIT
return function()
return {
n = 0,
--- Insert a value into the QIT at the end.
---@param self QIT
---@param value any The value to be inserted.
Insert = function(self, value)
self.n = self.n + 1
self[self.n] = value
end,
--- Insert a value into the QIT at the beginning.
---@param self QIT
---@param value any The value to be inserted.
Push = function(self, value)
table.insert(self, 1, value)
self.n = self.n + 1
end,
--- Remove a value from the end of the QIT.
---@param self QIT
---@param i integer? Position to remove from, if you want to.
---@return any value The value removed.
Remove = function(self, i)
if self.n > 0 then
local value = self[i or self.n]
if value ~= nil then
self[i or self.n] = nil
self.n = self.n - 1
end
return value
end
end,
--- Remove a value from the beginning of the QIT.
---@param self QIT
---@return any value The value removed.
Drop = function(self)
local value = table.remove(self, 1)
if value ~= nil then
self.n = self.n - 1
end
return value
end,
--- Remove all extra fields so this is just a normal array.
---@param self QIT
---@return self self
Clean = function(self)
self.Insert = nil
self.Push = nil
self.Remove = nil
self.Drop = nil
self.Clean = nil
return self
end
}
end