@@ -99,17 +99,11 @@ open class AVLTree<Key: Comparable, Payload> {
99
99
100
100
extension TreeNode {
101
101
public func minimum( ) -> TreeNode ? {
102
- if let leftChild = self . leftChild {
103
- return leftChild. minimum ( )
104
- }
105
- return self
102
+ return leftChild? . minimum ( ) ?? self
106
103
}
107
104
108
105
public func maximum( ) -> TreeNode ? {
109
- if let rightChild = self . rightChild {
110
- return rightChild. maximum ( )
111
- }
112
- return self
106
+ return rightChild? . maximum ( ) ?? self
113
107
}
114
108
}
115
109
@@ -120,11 +114,7 @@ extension AVLTree {
120
114
}
121
115
122
116
public func search( input: Key ) -> Payload ? {
123
- if let result = search ( key: input, node: root) {
124
- return result. payload
125
- } else {
126
- return nil
127
- }
117
+ return search ( key: input, node: root) ? . payload
128
118
}
129
119
130
120
fileprivate func search( key: Key , node: Node ? ) -> Node ? {
@@ -385,11 +375,7 @@ extension TreeNode: CustomDebugStringConvertible {
385
375
386
376
extension AVLTree : CustomDebugStringConvertible {
387
377
public var debugDescription : String {
388
- if let root = root {
389
- return root. debugDescription
390
- } else {
391
- return " [] "
392
- }
378
+ return root? . debugDescription ?? " [] "
393
379
}
394
380
}
395
381
@@ -409,10 +395,6 @@ extension TreeNode: CustomStringConvertible {
409
395
410
396
extension AVLTree : CustomStringConvertible {
411
397
public var description : String {
412
- if let root = root {
413
- return root. description
414
- } else {
415
- return " [] "
416
- }
398
+ return root? . description ?? " [] "
417
399
}
418
400
}
0 commit comments