3
3
/// stored contain a value, but are ordered or retrieved according to a key.
4
4
public protocol KeyValuePair : Comparable {
5
5
6
- associatedtype K : Comparable , Hashable
7
- associatedtype V : Comparable , Hashable
8
-
9
- // Identifier used in many algorithms to search by, order by, etc
10
- var key : K { get set }
11
-
12
- // A data container
13
- var value : V { get set }
14
-
15
-
16
- /// Initializer
17
- ///
18
- /// - Parameters:
19
- /// - key: Identifier used in many algorithms to search by, order by, etc.
20
- /// - value: A data container.
21
- init ( key: K , value: V )
22
-
23
-
24
- /// Creates a copy
25
- ///
26
- /// - Abstract: Conformers of this class can be either value or reference types.
27
- /// Some algorithms might need to guarantee that a conformer instance gets copied.
28
- /// This will perform an innecessary in the case of value types.
29
- /// TODO: is there a better way?
30
- /// - Returns: A new instance with the old one's values copied.
31
- func copy( ) -> Self
6
+ associatedtype K : Comparable , Hashable
7
+ associatedtype V : Comparable , Hashable
8
+
9
+ // Identifier used in many algorithms to search by, order by, etc
10
+ var key : K { get set }
11
+
12
+ // A data container
13
+ var value : V { get set }
14
+
15
+
16
+ /// Initializer
17
+ ///
18
+ /// - Parameters:
19
+ /// - key: Identifier used in many algorithms to search by, order by, etc.
20
+ /// - value: A data container.
21
+ init ( key: K , value: V )
22
+
23
+
24
+ /// Creates a copy
25
+ ///
26
+ /// - Abstract: Conformers of this class can be either value or reference types.
27
+ /// Some algorithms might need to guarantee that a conformer instance gets copied.
28
+ /// This will perform an innecessary in the case of value types.
29
+ /// TODO: is there a better way?
30
+ /// - Returns: A new instance with the old one's values copied.
31
+ func copy( ) -> Self
32
32
}
33
33
34
34
35
35
/// Conformance to Equatable and Comparable protocols
36
36
extension KeyValuePair {
37
37
38
- // MARK: - Equatable protocol
39
- public static func == ( lhs: Self , rhs: Self ) -> Bool {
40
- return lhs. key == rhs. key
41
- }
42
-
43
-
44
-
45
- // MARK: - Comparable protocol
46
-
47
- public static func < ( lhs: Self , rhs: Self ) -> Bool {
48
- return lhs. key < rhs. key
49
- }
50
-
51
- public static func <= ( lhs: Self , rhs: Self ) -> Bool {
52
- return lhs. key <= rhs. key
53
- }
54
-
55
- public static func >= ( lhs: Self , rhs: Self ) -> Bool {
56
- return lhs. key >= rhs. key
57
- }
58
-
59
- public static func > ( lhs: Self , rhs: Self ) -> Bool {
60
- return lhs. key > rhs. key
61
- }
38
+ // MARK: - Equatable protocol
39
+ public static func == ( lhs: Self , rhs: Self ) -> Bool {
40
+ return lhs. key == rhs. key
41
+ }
42
+
43
+
44
+
45
+ // MARK: - Comparable protocol
46
+
47
+ public static func < ( lhs: Self , rhs: Self ) -> Bool {
48
+ return lhs. key < rhs. key
49
+ }
50
+
51
+ public static func <= ( lhs: Self , rhs: Self ) -> Bool {
52
+ return lhs. key <= rhs. key
53
+ }
54
+
55
+ public static func >= ( lhs: Self , rhs: Self ) -> Bool {
56
+ return lhs. key >= rhs. key
57
+ }
58
+
59
+ public static func > ( lhs: Self , rhs: Self ) -> Bool {
60
+ return lhs. key > rhs. key
61
+ }
62
62
}
63
63
64
64
@@ -67,11 +67,11 @@ extension KeyValuePair {
67
67
/// are Integers.
68
68
struct IntegerPair : KeyValuePair {
69
69
70
- // MARK - KeyValuePair protocol
71
- var key : Int
72
- var value : Int
73
-
74
- func copy( ) -> IntegerPair {
75
- return IntegerPair ( key: self . key, value: self . value)
76
- }
70
+ // MARK - KeyValuePair protocol
71
+ var key : Int
72
+ var value : Int
73
+
74
+ func copy( ) -> IntegerPair {
75
+ return IntegerPair ( key: self . key, value: self . value)
76
+ }
77
77
}
0 commit comments