summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/lib/Stack.lua
blob: 75084b6e38bf4c514975416122652b9e64facc78 (plain)
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
-- 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$


--- 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