-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsxm_Set.m
50 lines (39 loc) · 1.08 KB
/
sxm_Set.m
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
classdef sxm_Set < handle
%SXM_SET Implements the Set ADT.
properties (SetAccess=protected)
card
elems
end
methods
function self = sxm_Set(L)
self.elems = sxm_List(unique(L));
self.card = length(self.elems);
end
function l = length(S)
l = S.card;
end
function s = size(S)
s = [1 S.card];
end
function r = in(S, e)
r = sxm_in(e, S.elems);
end
function add(S, e)
S.elems.append(e);
S.card = length(S.elems);
end
function remove(S, e)
S.elems.remove(e);
S.card = length(S.elems);
end
function U = union(S, T)
U = sxm_Set(union(S.elems, T.elems));
end
function I = intersection(S, T)
I = sxm_Set(intersect(S.elems, T.elems));
end
function D = minus(S, T)
D = sxm_Set(setdiff(S.elems, T.elems));
end
end
end