- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueue.lua
More file actions
Latest commit
68 lines (52 loc) · 1.36 KB
/
Copy pathqueue.lua
File metadata and controls
68 lines (52 loc) · 1.36 KB
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
66
67
68
localHERE= (...):match("(.-)[^%.]+$")
localBase=require(HERE..".base")
---@classQueue
localqueue= {}
queue.__index=queue
queue.__extVersion="0.0.5"
-------------------------------------------------
---@returnQueue
functionqueue.new(t)
returnsetmetatable(tor {}, queue)
end
--- Adds an element to the rear of the queue.
functionqueue:enqueue(value)
table.insert(self, value)
end
queue.add=queue.enqueue
--- Removes and returns the element from the front of the queue.
functionqueue:dequeue()
returntable.remove(self, 1)
end
queue.remove=queue.dequeue
--- Returns the element at the front of the queue without removing it.
functionqueue:peek()
returnself[1]
end
queue.front=queue.peek
--- Clears the queue while keeping same memory address.<br>
--- Use queue.new unless you need the same memory address.
functionqueue:clear()
forkinipairs(self) do
self[k] =nil
end
end
--- Checks if the queue is empty and returns a boolean value.
functionqueue:isEmpty()
return#self==0
end
functionqueue:contains(value)
fori, vinipairs(self) do
ifv==valuethenreturntrue, iend
end
returnfalse
end
functionqueue:iterate()
returnipairs(self)
end
---Create copy of the passed Queue recursively.
queue.clone=Base.clone
---Create a simple clone.
queue.shallowClone=Base.shallowClone
queue.toString=table.concat
returnqueue