forked from studoverse/Kotlift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
28_set.swift
46 lines (39 loc) · 913 Bytes
/
28_set.swift
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
func main(args: [String]) {
// Constructors
let hashSet0 = Set<String>()
let linkedHashSet0 = Set<String>()
let set0 = Set<String>()
let set1 = Set(arrayLiteral: 1)
let set2 = Set(arrayLiteral: 1, 2, 1)
var hashSet = Set(arrayLiteral: 1)
var linkedSet = Set(arrayLiteral: 2)
var mutableSet = Set(arrayLiteral: 3)
// Basic calls
print("\(set1) (1)")
print("\(set2) (1, 2)")
print("\(set2.size) (2)")
hashSet.add(2)
linkedSet.addAll(linkedSet)
mutableSet.remove(3)
print(hashSet)
if hashSet.size != 2 {
print("ERROR: hashSet.size")
}
print(linkedSet)
if linkedSet.size != 1 {
print("ERROR: linkedSet.size")
}
print(mutableSet)
if mutableSet.size != 0 {
print("ERROR: mutableSet.size")
}
if !set0.isEmpty() {
print("ERROR: set0.isEmpty()")
}
print("\(hashSet) ([2, 1])")
// Iteration
for k in set2 {
print("\(k)")
}
}
main([])