forked from FAForever/fa
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetutils.lua
More file actions
85 lines (67 loc) · 1.33 KB
/
setutils.lua
File metadata and controls
85 lines (67 loc) · 1.33 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
-- Let table t = {k_1 = v_1, k_2 = v_2, ..., k_n = v_n} represent the set S.(∀s ∈ S ∃ k ∈ t.(v = true)).
--
-- Utility functions for working with this type of set.
--- Returns a ∪ b as a new set
function Union(a, b)
local u = {}
table.print(a)
table.print(b)
for k, v in a do
u[k] = v or u[k]
end
for k, v in b do
u[k] = v or u[k]
end
return u
end
--- Replaces a with a ∪ b
function DestructiveUnion(a, b)
for k, v in b do
a[k] = v or nil
end
return a
end
--- Returns a ∩ b as a new set
function Intersection(a, b)
local i = {}
for k, v in a do
if v and b[k] then
i[k] = true
end
end
for k, v in b do
if v and a[k] then
i[k] = true
end
end
return i
end
--- Returns a \ b as a new set
function Subtract(a, b)
local s = {}
for k, v in a do
if v and not b[k] then
s[k] = true
end
end
return s
end
--- Returns the set S = {a ∈ A.p(a)}
function PredicateFilter(A, p)
local s = {}
for k, v in A do
if v and p(k) then
s[k] = true
end
end
return s
end
--- Returns true iff A is the empty set
function Empty(A)
for k, v in A do
if v then
return false
end
end
return true
end