Content-Length: 776954 | pFad | http://github.com/EthanDoan/Algorithm/commit/bbff1fe198da4e92fe0cf6a13604326efcd52bd2

50 development: progression commit · EthanDoan/Algorithm@bbff1fe · GitHub
Skip to content

Commit bbff1fe

Browse files
author
Daniel Dahan
committed
development: progression commit
1 parent ed9721c commit bbff1fe

10 files changed

+735
-831
lines changed

Sources/Algorithm+Array.swift

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,13 @@ extension Array where Element: Equatable {
6464
self.remove(object: $0)
6565
}
6666
}
67-
}
6867

69-
extension Array: Probable {
70-
/**
68+
/**
7169
The total count for the given Elements.
7270
- Parameter of elements: A list of Elements.
7371
- Returns: An Int.
7472
*/
75-
public func count<Element: Equatable>(of elements: Element...) -> Int {
73+
public func count(of elements: Element...) -> Int {
7674
return count(of: elements)
7775
}
7876

@@ -81,11 +79,11 @@ extension Array: Probable {
8179
- Parameter of elements: An Array of Elements.
8280
- Returns: An Int.
8381
*/
84-
public func count<Element: Equatable>(of elements: [Element]) -> Int {
82+
public func count(of elements: [Element]) -> Int {
8583
var c = 0
8684
for e in elements {
8785
for x in self {
88-
if e == x as? Element {
86+
if e == x {
8987
c += 1
9088
}
9189
}
@@ -98,7 +96,7 @@ extension Array: Probable {
9896
- Parameter of elements: A list of Elements.
9997
- Returns: A Double.
10098
*/
101-
public func probability<Element: Equatable>(of elements: Element...) -> Double {
99+
public func probability(of elements: Element...) -> Double {
102100
return probability(of: elements)
103101
}
104102

@@ -107,7 +105,7 @@ extension Array: Probable {
107105
- Parameter of elements: An Array of Elements.
108106
- Returns: A Double.
109107
*/
110-
public func probability<Element: Equatable>(of elements: [Element]) -> Double {
108+
public func probability(of elements: [Element]) -> Double {
111109
return 0 < count ? Double(count(of: elements)) / Double(count) : 0
112110
}
113111

@@ -116,7 +114,7 @@ extension Array: Probable {
116114
- Parameter of elements: A list of Elements.
117115
- Returns: A Double.
118116
*/
119-
public func probability(of block: @escaping (Element) -> Bool) -> Double {
117+
public func probability(execute block: @escaping (Element) -> Bool) -> Double {
120118
guard 0 < count else {
121119
return 0
122120
}
@@ -137,7 +135,7 @@ extension Array: Probable {
137135
- Parameter elements: A list of Elements.
138136
- Returns: A Double.
139137
*/
140-
public func expectedValue<Element: Equatable>(trials: Int, for elements: Element...) -> Double {
138+
public func expectedValue(trials: Int, for elements: Element...) -> Double {
141139
return expectedValue(trials: trials, for: elements)
142140
}
143141

@@ -147,7 +145,7 @@ extension Array: Probable {
147145
- Parameter elements: An Array of Elements.
148146
- Returns: A Double.
149147
*/
150-
public func expectedValue<Element: Equatable>(trials: Int, for elements: [Element]) -> Double {
148+
public func expectedValue(trials: Int, for elements: [Element]) -> Double {
151149
return Double(trials) * probability(of: elements)
152150
}
153151
}

Sources/DoublyLinkedList.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public struct DoublyLinkedList<Element>: CustomStringConvertible, Sequence {
6060
- Returns: A String.
6161
*/
6262
public var description: String {
63-
var output: String = "("
63+
var output = "("
6464
var c = 0
6565
var x = head
6666
while nil !== x {

Sources/Probable.swift

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,47 +29,49 @@
2929
*/
3030

3131
internal protocol Probable {
32+
associatedtype Element: Equatable
33+
3234
/**
3335
The instance count of elements.
3436
- Parameter of elements: A list of Elements
3537
- Returns: An Int.
3638
*/
37-
func count<Element: Equatable>(of elements: Element...) -> Int
39+
func count(of elements: Element...) -> Int
3840

3941
/**
4042
The instance count of elements.
4143
- Parameter of elements: An Array of Elements.
4244
- Returns: An Int.
4345
*/
44-
func count<Element: Equatable>(of elements: [Element]) -> Int
46+
func count(of elements: [Element]) -> Int
4547

4648
/**
47-
The probability of elements.
49+
The probability of given elements.
4850
- Parameter of elements: A list of Elements.
4951
- Returns: A Double.
5052
*/
51-
func probability<Element: Equatable>(of elements: Element...) -> Double
53+
func probability(of elements: Element...) -> Double
5254

5355
/**
54-
The probability of elements.
56+
The probability of given elements.
5557
- Parameter of elements: An Array of Elements.
5658
- Returns: A Double.
5759
*/
58-
func probability<Element: Equatable>(of elements: [Element]) -> Double
60+
func probability(of elements: [Element]) -> Double
5961

6062
/**
61-
The expected value of elements based on a number of trials.
63+
The expected value of given elements based on a number of trials.
6264
- Parameter trials: An Int.
6365
- Parameter for elements: A list of Elements.
6466
- Returns: A Double.
6567
*/
66-
func expectedValue<Element: Equatable>(trials: Int, for elements: Element...) -> Double
68+
func expectedValue(trials: Int, for elements: Element...) -> Double
6769

6870
/**
69-
The expected value of elements based on a number of trials.
71+
The expected value of given elements based on a number of trials.
7072
- Parameter trials: An Int.
7173
- Parameter for elements: An Array of Elements.
7274
- Returns: A Double.
7375
*/
74-
func expectedValue<Element: Equatable>(trials: Int, for elements: [Element]) -> Double
76+
func expectedValue(trials: Int, for elements: [Element]) -> Double
7577
}

Sources/RedBlackTree.swift

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ public struct RedBlackTree<Key: Comparable, Value>: Probable, Collection, Custom
7575
- returns: String
7676
*/
7777
public var description: String {
78-
var output: String = "["
79-
let l: Int = count - 1
78+
var output = "["
79+
let l = count - 1
8080
for i in 0..<count {
8181
output += "\(self[i])"
8282
if i != l {
@@ -119,7 +119,7 @@ public struct RedBlackTree<Key: Comparable, Value>: Probable, Collection, Custom
119119

120120
/**
121121
:name: startIndex
122-
:description: Conforms to the CollectionType Protocol.
122+
:description: Conforms to the Collection Protocol.
123123
- returns: Int
124124
*/
125125
public var startIndex: Int {
@@ -128,7 +128,7 @@ public struct RedBlackTree<Key: Comparable, Value>: Probable, Collection, Custom
128128

129129
/**
130130
:name: endIndex
131-
:description: Conforms to the CollectionType Protocol.
131+
:description: Conforms to the Collection Protocol.
132132
- returns: Int
133133
*/
134134
public var endIndex: Int {
@@ -212,7 +212,7 @@ public struct RedBlackTree<Key: Comparable, Value>: Probable, Collection, Custom
212212
/**
213213
The probability of elements.
214214
*/
215-
public func probability(_ block: (Key, Value?) -> Bool) -> Double {
215+
public func probability(execute block: (Key, Value?) -> Bool) -> Double {
216216
if 0 == count {
217217
return 0
218218
}
@@ -246,7 +246,7 @@ public struct RedBlackTree<Key: Comparable, Value>: Probable, Collection, Custom
246246
- returns: Bool
247247
*/
248248
@discardableResult
249-
mutating public func insert(_ key: Key, value: Value?) -> Bool {
249+
mutating public func insert(value: Value?, for key: Key) -> Bool {
250250
return sentinel !== internalInsert(key, value: value)
251251
}
252252

@@ -255,18 +255,18 @@ public struct RedBlackTree<Key: Comparable, Value>: Probable, Collection, Custom
255255
:description: Inserts a list of (Key, Value?) pairs.
256256
- parameter nodes: (Key, Value?)... Elements to insert.
257257
*/
258-
mutating public func insert(_ nodes: (Key, Value?)...) {
259-
insert(nodes)
258+
mutating public func insert(nodes: (Key, Value?)...) {
259+
insert(nodes: nodes)
260260
}
261261

262262
/**
263263
:name: insert
264264
:description: Inserts an array of (Key, Value?) pairs.
265-
- parameter nodes: Array<(Key, Value?)> Elements to insert.
265+
- parameter nodes: [(Key, Value?)] Elements to insert.
266266
*/
267-
mutating public func insert(_ nodes: Array<(Key, Value?)>) {
267+
mutating public func insert(nodes: [(Key, Value?)]) {
268268
for (k, v) in nodes {
269-
insert(k, value: v)
269+
insert(value: v, for: k)
270270
}
271271
}
272272

@@ -277,8 +277,8 @@ public struct RedBlackTree<Key: Comparable, Value>: Probable, Collection, Custom
277277
the given key value will be removed.
278278
- returns: RedBlackTree<Key, Value>?
279279
*/
280-
mutating public func removeValueForKeys(_ keys: Key...) {
281-
return removeValueForKeys(keys)
280+
mutating public func removeValue(for keys: Key...) {
281+
return removeValue(for: keys)
282282
}
283283

284284
/**
@@ -288,7 +288,7 @@ public struct RedBlackTree<Key: Comparable, Value>: Probable, Collection, Custom
288288
the given key will be removed.
289289
- returns: RedBlackTree<Key, Value>?
290290
*/
291-
mutating public func removeValueForKeys(_ keys: Array<Key>) {
291+
mutating public func removeValue(for keys: [Key]) {
292292
for x in keys {
293293
var z = internalRemoveValueForKey(x)
294294
while sentinel !== z {
@@ -324,8 +324,8 @@ public struct RedBlackTree<Key: Comparable, Value>: Probable, Collection, Custom
324324
If the tree allows non-unique keys, then all keys matching
325325
the given key value will be updated.
326326
*/
327-
mutating public func updateValue(_ value: Value?, forKey: Key) {
328-
internalUpdateValue(value, forKey: forKey, node: root)
327+
mutating public func update(value: Value?, for key: Key) {
328+
internalUpdateValue(value, forKey: key, node: root)
329329
}
330330

331331
/**
@@ -334,7 +334,7 @@ public struct RedBlackTree<Key: Comparable, Value>: Probable, Collection, Custom
334334
in isUniquelyKeyed tree of a given keyed node.
335335
- returns: Value?
336336
*/
337-
public func findValueForKey(_ key: Key) -> Value? {
337+
public func findValue(for key: Key) -> Value? {
338338
return internalFindNodeForKey(key).value
339339
}
340340

@@ -381,7 +381,7 @@ public struct RedBlackTree<Key: Comparable, Value>: Probable, Collection, Custom
381381
:description: Returns the Index of a given member, or nil if the member is not present in the set.
382382
- returns: Int
383383
*/
384-
public func indexOf(_ key: Key) -> Int {
384+
public func index(of key: Key) -> Int {
385385
let x = internalFindNodeForKey(key)
386386
return sentinel == x ? -1 : internalOrder(x) - 1
387387
}

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/EthanDoan/Algorithm/commit/bbff1fe198da4e92fe0cf6a13604326efcd52bd2

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy