Depend on "set" LuaRock, added doc/

This commit is contained in:
Wouter Scherphof 2013-03-27 11:40:19 +01:00
parent 87fc36650c
commit 3af809df9a
5 changed files with 30 additions and 88 deletions

14
.gitignore vendored
View File

@ -1,2 +1,16 @@
# LuaRocks #
######################
lib/
share/
bin/
# OS generated files #
######################
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
Icon?
ehthumbs.db
Thumbs.db

View File

@ -1,4 +1,5 @@
local Set = require "Set"
require("luarocks.loader")
local Set = require("Set")
local ElementNode = {}
ElementNode.mt = {__index = ElementNode}

87
Set.lua
View File

@ -1,87 +0,0 @@
local Set = {}
Set.mt = {__index = Set}
function Set:new(t)
local instance = {}
if type(t) == "table" then
if #t > 0 then
for _,v in ipairs(t) do
instance[v] = true
end
else
for k in pairs(t) do
instance[k] = true
end
end
else
instance = {t}
end
return setmetatable(instance, Set.mt)
end
function Set:add(e)
self[e] = true
end
function Set:remove(e)
self[e] = nil
end
-- Union
Set.mt.__add = function (a, b)
local res = Set:new()
if getmetatable(a) ~= Set.mt then a = Set:new(a) end
if getmetatable(b) ~= Set.mt then b = Set:new(b) end
for k in pairs(a) do res[k] = true end
for k in pairs(b) do res[k] = true end
return res
end
-- Subtraction
Set.mt.__sub = function (a, b)
local res = Set:new()
if getmetatable(a) ~= Set.mt then a = Set:new(a) end
if getmetatable(b) ~= Set.mt then b = Set:new(b) end
for k in pairs(a) do res[k] = true end
for k in pairs(b) do res[k] = nil end
return res
end
-- Intersection
Set.mt.__mul = function (a, b)
local res = Set:new()
if getmetatable(a) ~= Set.mt then a = Set:new(a) end
if getmetatable(b) ~= Set.mt then b = Set:new(b) end
for k in pairs(a) do
res[k] = b[k]
end
return res
end
-- String representation
Set.mt.__tostring = function (set)
local s = "{"
local sep = ""
for k in pairs(set) do
s = s .. sep .. k
sep = ", "
end
return s .. "}"
end
function Set:len()
local num = 0
for _ in pairs(self) do
num = num + 1
end
return num
end
function Set:tolist()
local res = {}
for k in pairs(self) do
table.insert(res, k)
end
return res
end
return Set

14
doc/README.html Normal file
View File

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<title>Htmlparser LuaRock Readme</title>
<meta charset="UTF-8">
<meta http-equiv="Refresh" content="3; url=http://wscherphof.github.com/lua-htmlparser/" />
</head>
<body>
<p>You are being redirected to the homepage of the
<a href="http://wscherphof.github.com/lua-htmlparser/">Htmlparser LuaRock</a>.
</p>
<p>If you are not redirected after a few seconds, please click on the link above!</p>
</body>
</html>