View on GitHub

LuaRock "set"

Straightforward Set library for Lua

Download this project as a .zip file Download this project as a tar.gz file

Install

Set is a listed LuaRock. Install using LuaRocks: luarocks install set

Dependencies

Set depends on Lua 5.2. lunitx is needed to run the tests and will be installed if not present

Usage

Start off with

require("luarocks.loader")
local Set = require("Set")

Then, to create a set:

local ilike = Set:new()

to add items to a set:

ilike:add("apples")
ilike:add("bananas")

or, we could have done:

local ilike = Set:new({"apples", "bananas"})

Let's have another set:

local ulike = Set:new({"apples", "strawberries"})

Then we can:

local welike     = ilike + ulike -- union:        apples, bananas, strawberries
local webothlike = ilike * ulike -- intersection: apples
local udontlike  = ilike - ulike -- subtraction:  bananas

Lastly, some conveniences:

ilike:len()  -- 2
local somethingilike = ilike:anelement()
print(ilike) -- {"apples", "bananas"}

Tests

See ./tst/init.lua

License

LGPL+; see ./doc/LICENSE