summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/lib/Stack.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/lib/Stack.lua')
-rw-r--r--Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/lib/Stack.lua61
1 files changed, 61 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/lib/Stack.lua b/Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/lib/Stack.lua
new file mode 100644
index 00000000000..11466c04961
--- /dev/null
+++ b/Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/lib/Stack.lua
@@ -0,0 +1,61 @@
+-- Copyright 2011 by Jannis Pohlmann
+-- Copyright 2012 by Till Tantau
+--
+-- This file may be distributed an/or modified
+--
+-- 1. under the LaTeX Project Public License and/or
+-- 2. under the GNU Public License
+--
+-- See the file doc/generic/pgf/licenses/LICENSE for more information
+
+-- @release $Header: /cvsroot/pgf/pgf/generic/pgf/graphdrawing/lua/pgf/gd/lib/Stack.lua,v 1.1 2012/11/27 17:24:26 tantau Exp $
+
+
+--- A Stack is a very simple wrapper around an array
+--
+--
+
+local Stack = {}
+Stack.__index = Stack
+
+
+-- Namespace
+require("pgf.gd.lib").Stack = Stack
+
+
+--- Create a new stack
+function Stack.new()
+ local stack = {}
+ setmetatable(stack, Stack)
+ return stack
+end
+
+
+--- Push an element on top of the stack
+function Stack:push(data)
+ self[#self+1] = data
+end
+
+
+--- Inspect (but not pop) the top element of a stack
+function Stack:peek()
+ return self[#self]
+end
+
+
+--- Pop an element from the top of the stack
+function Stack:pop()
+ return table.remove(self, #self)
+end
+
+
+--- Get the height of the stack
+function Stack:getSize()
+ return #self
+end
+
+
+
+-- done
+
+return Stack \ No newline at end of file