Quantcast

Rename OvaleDeque to OvaleQueue and implement LIFO and FIFO structures.

Johnny C. Lam [05-21-13 - 05:11]
Rename OvaleDeque to OvaleQueue and implement LIFO and FIFO structures.

git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@923 d5049fe3-3747-40f7-a4b5-f36d6801af5f
Filename
Ovale.toc
OvaleDamageTaken.lua
OvaleDeque.lua
OvaleQueue.lua
compiler.pl
diff --git a/Ovale.toc b/Ovale.toc
index 92cccbd..83e42b0 100644
--- a/Ovale.toc
+++ b/Ovale.toc
@@ -31,12 +31,12 @@ Ovale.lua

 # Modules with no dependencies
 OvaleActionBar.lua
-OvaleDeque.lua
 OvaleEnemies.lua
 OvaleEquipement.lua
 OvaleGUID.lua
 OvalePaperDoll.lua
 OvalePool.lua
+OvaleQueue.lua
 OvaleRecount.lua
 OvaleSkada.lua
 OvaleStance.lua
diff --git a/OvaleDamageTaken.lua b/OvaleDamageTaken.lua
index b344318..33e8030 100644
--- a/OvaleDamageTaken.lua
+++ b/OvaleDamageTaken.lua
@@ -14,10 +14,10 @@ local OvaleDamageTaken = Ovale:NewModule("OvaleDamageTaken", "AceEvent-3.0")
 Ovale.OvaleDamageTaken = OvaleDamageTaken

 --<private-static-properties>
-local OvaleDeque = Ovale.OvaleDeque
 local OvaleGUID = Ovale.OvaleGUID
 local OvaleFuture = Ovale.OvaleFuture
 local OvalePool = Ovale.OvalePool
+local OvaleQueue = Ovale.OvaleQueue

 local select = select

@@ -26,7 +26,7 @@ local self_player_guid = nil
 -- Damage event pool.
 local self_pool = OvalePool:NewPool("OvaleDamageTaken_pool")
 -- Damage event queue: new events are inserted at the front of the queue.
-local self_damageEvent = OvaleDeque:New("OvaleDamageTaken_damageEvent")
+local self_damageEvent = OvaleQueue:NewDeque("OvaleDamageTaken_damageEvent")
 -- Time window (past number of seconds) for which damage events are stored.
 local DAMAGE_TAKEN_WINDOW = 20

diff --git a/OvaleDeque.lua b/OvaleDeque.lua
deleted file mode 100644
index 31eea28..0000000
--- a/OvaleDeque.lua
+++ /dev/null
@@ -1,105 +0,0 @@
---[[--------------------------------------------------------------------
-    Ovale Spell Priority
-    Copyright (C) 2013 Johnny C. Lam
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License in the LICENSE
-    file accompanying this program.
---]]--------------------------------------------------------------------
-
--- Double-ended queue.
-local _, Ovale = ...
-local OvaleDeque = {}
-Ovale.OvaleDeque = OvaleDeque
-
---<public-static-properties>
-OvaleDeque.name = "OvaleDeque"
-OvaleDeque.first = 0
-OvaleDeque.last = -1
---</public-static-properties>
-
---<private-static-methods>
-local function BackToFrontIterator(invariant, control)
-	control = control - 1
-	local element = invariant[control]
-	if element then
-		return control, element
-	end
-end
-
-local function FrontToBackIterator(invariant, control)
-	control = control + 1
-	local element = invariant[control]
-	if element then
-		return control, element
-	end
-end
---</private-static-methods>
-
---<public-static-methods>
-function OvaleDeque:New(name)
-	obj = { name = name, first = 0, last = -1 }
-	setmetatable(obj, { __index = self })
-	return obj
-end
-
-function OvaleDeque:InsertFront(element)
-	local first = self.first - 1
-	self.first = first
-	self[first] = element
-end
-
-function OvaleDeque:InsertBack(element)
-	local last = self.last + 1
-	self.last = last
-	self[last] = element
-end
-
-function OvaleDeque:RemoveFront()
-	local first = self.first
-	local element = self[first]
-	if element then
-		self[first] = nil
-		self.first = first + 1
-	end
-	return element
-end
-
-function OvaleDeque:RemoveBack()
-	local last = self.last
-	local element = self[last]
-	if element then
-		self[last] = nil
-		self.last = last - 1
-	end
-	return element
-end
-
-function OvaleDeque:Front()
-	return self[self.first]
-end
-
-function OvaleDeque:Back()
-	return self[self.last]
-end
-
-function OvaleDeque:BackToFrontIterator()
-	return BackToFrontIterator, self, self.last + 1
-end
-
-function OvaleDeque:FrontToBackIterator()
-	return FrontToBackIterator, self, self.first - 1
-end
-
-function OvaleDeque:Reset()
-	for i in self:BackToFrontIterator() do
-		self[i] = nil
-	end
-	self.first = 0
-	self.last = -1
-end
-
-function OvaleDeque:Debug()
-	Ovale:FormatPrint("Deque %s has %d item(s), first=%d, last=%d.", self.name, self.last - self.first + 1, self.first, self.last)
-end
---</public-static-methods>
diff --git a/OvaleQueue.lua b/OvaleQueue.lua
new file mode 100644
index 0000000..ce0c570
--- /dev/null
+++ b/OvaleQueue.lua
@@ -0,0 +1,119 @@
+--[[--------------------------------------------------------------------
+    Ovale Spell Priority
+    Copyright (C) 2013 Johnny C. Lam
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License in the LICENSE
+    file accompanying this program.
+--]]--------------------------------------------------------------------
+
+-- Double-ended queue.
+local _, Ovale = ...
+local OvaleQueue = {}
+Ovale.OvaleQueue = OvaleQueue
+
+--<public-static-properties>
+OvaleQueue.name = "OvaleQueue"
+OvaleQueue.first = 0
+OvaleQueue.last = -1
+--</public-static-properties>
+
+--<private-static-methods>
+local function BackToFrontIterator(invariant, control)
+	control = control - 1
+	local element = invariant[control]
+	if element then
+		return control, element
+	end
+end
+
+local function FrontToBackIterator(invariant, control)
+	control = control + 1
+	local element = invariant[control]
+	if element then
+		return control, element
+	end
+end
+--</private-static-methods>
+
+--<public-static-methods>
+function OvaleQueue:NewDeque(name)
+	obj = { name = name, first = 0, last = -1 }
+	setmetatable(obj, { __index = self })
+	return obj
+end
+
+function OvaleQueue:InsertFront(element)
+	local first = self.first - 1
+	self.first = first
+	self[first] = element
+end
+
+function OvaleQueue:InsertBack(element)
+	local last = self.last + 1
+	self.last = last
+	self[last] = element
+end
+
+function OvaleQueue:RemoveFront()
+	local first = self.first
+	local element = self[first]
+	if element then
+		self[first] = nil
+		self.first = first + 1
+	end
+	return element
+end
+
+function OvaleQueue:RemoveBack()
+	local last = self.last
+	local element = self[last]
+	if element then
+		self[last] = nil
+		self.last = last - 1
+	end
+	return element
+end
+
+function OvaleQueue:Front()
+	return self[self.first]
+end
+
+function OvaleQueue:Back()
+	return self[self.last]
+end
+
+function OvaleQueue:BackToFrontIterator()
+	return BackToFrontIterator, self, self.last + 1
+end
+
+function OvaleQueue:FrontToBackIterator()
+	return FrontToBackIterator, self, self.first - 1
+end
+
+function OvaleQueue:Reset()
+	for i in self:BackToFrontIterator() do
+		self[i] = nil
+	end
+	self.first = 0
+	self.last = -1
+end
+
+function OvaleQueue:Debug()
+	Ovale:FormatPrint("Queue %s has %d item(s), first=%d, last=%d.", self.name, self.last - self.first + 1, self.first, self.last)
+end
+--</public-static-methods>
+
+--<public-static-properties>
+-- Queue (LIFO) methods
+OvaleQueue.NewQueue = OvaleQueue.NewDeque
+OvaleQueue.Insert = OvaleQueue.InsertBack
+OvaleQueue.Remove = OvaleQueue.RemoveFront
+OvaleQueue.Iterator = OvaleQueue.FrontToBackIterator
+
+-- Stack (FIFO) methods
+OvaleQueue.NewStack = OvaleQueue.NewDeque
+OvaleQueue.Push = OvaleQueue.InsertFront
+OvaleQueue.Pop = OvaleQueue.RemoveFront
+OvaleQueue.Top = OvaleQueue.Front
+--</public-static-properties>
diff --git a/compiler.pl b/compiler.pl
index 2f3d27e..0df88e7 100644
--- a/compiler.pl
+++ b/compiler.pl
@@ -92,7 +92,7 @@ $p{Skada}{total} = true;

 $sp{Ovale}{OvaleBestAction} = true;
 $sp{Ovale}{OvaleCondition} = true;
-$sp{Ovale}{OvaleDeque} = true;
+$sp{Ovale}{OvaleQueue} = true;
 $sp{Ovale}{OvalePool} = true;
 $sp{Ovale}{OvaleSkada} = true;
 $sp{Ovale}{OvaleState} = true;