Repository navigation
Expand file tree
/
Copy pathset.pxi
More file actions
78 lines (66 loc) · 1.74 KB
/
Copy pathset.pxi
File metadata and controls
78 lines (66 loc) · 1.74 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
(ns pixie.set
(:require [pixie.stdlib :as std]))
(defn- -must-be-set [s]
(if (set? s)
s
(throw [:pixie.stdlib/InvalidArgumentException
(str "Not a set: " s)])))
(defn- -must-be-sets [& sets]
(doseq [set sets]
(-must-be-set set)))
(defn- -union [s t]
(-must-be-sets s t)
(if (< (count s) (count t))
(into t s)
(into s t)))
(defn union
"Returns a set that is the union of the input sets."
([] #{})
([s] (-must-be-set s))
([s t]
(-union s t))
([s t & sets]
(reduce -union (-union s t) sets)))
(defn- -difference [s t]
(-must-be-sets s t)
(into #{} (filter #(not (contains? t %))) s))
(defn difference
"Returns a set that is the difference of the input sets."
([] #{})
([s] (-must-be-set s))
([s t]
(-difference s t))
([s t & sets]
(reduce -difference (-difference s t) sets)))
(defn- -intersection [s t]
(-must-be-set s)
(-must-be-set t)
(into #{} (filter #(contains? s %)) t))
(defn intersection
"Returns a set that is the intersection of the input sets."
([] #{})
([s] (-must-be-set s))
([s t]
(-intersection s t))
([s t & sets]
(reduce -intersection (-intersection s t) sets)))
(defn subset?
"Returns true if the first set is a subset of the second."
[s t]
(-must-be-sets s t)
(and (<= (count s) (count t))
(every? #(contains? t %) (vec s))))
(defn strict-subset?
"Returns true if the first set is a subset of the second."
[s t]
(-must-be-sets s t)
(and (< (count s) (count t))
(subset? s t)))
(defn superset?
"Returns true if the first set is a superset of the second."
[s t]
(subset? t s))
(defn strict-superset?
"Returns true if the first set is a strict superset of the second."
[s t]
(strict-subset? t s))