Skip to content

Commit 4ccf6a9

Browse files
author
Daniel Dahan
committed
wip: updated spacing
1 parent 70df7d1 commit 4ccf6a9

25 files changed

+2231
-2430
lines changed

Algorithm.xcodeproj/project.pbxproj

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,6 @@
8989
65744D421C554F410011C977 /* SortedMultiSet.swift in Headers */ = {isa = PBXBuildFile; fileRef = 65744CE91C554EDA0011C977 /* SortedMultiSet.swift */; settings = {ATTRIBUTES = (Public, ); }; };
9090
65744D431C554F410011C977 /* SortedSet.swift in Headers */ = {isa = PBXBuildFile; fileRef = 65744CEA1C554EDA0011C977 /* SortedSet.swift */; settings = {ATTRIBUTES = (Public, ); }; };
9191
65744D441C554F410011C977 /* Stack.swift in Headers */ = {isa = PBXBuildFile; fileRef = 65744CEB1C554EDA0011C977 /* Stack.swift */; settings = {ATTRIBUTES = (Public, ); }; };
92-
961E6C3D1DDF9E64004E6C93 /* SampleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 961E6C3C1DDF9E64004E6C93 /* SampleTests.swift */; };
93-
961E6C3E1DDF9E64004E6C93 /* SampleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 961E6C3C1DDF9E64004E6C93 /* SampleTests.swift */; };
9492
/* End PBXBuildFile section */
9593

9694
/* Begin PBXContainerItemProxy section */
@@ -143,7 +141,6 @@
143141
65744D111C554F0E0011C977 /* SortedMultiSetTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SortedMultiSetTests.swift; sourceTree = "<group>"; };
144142
65744D121C554F0E0011C977 /* SortedSetTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SortedSetTest.swift; sourceTree = "<group>"; };
145143
65744D131C554F0E0011C977 /* StackTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StackTests.swift; sourceTree = "<group>"; };
146-
961E6C3C1DDF9E64004E6C93 /* SampleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SampleTests.swift; sourceTree = "<group>"; };
147144
/* End PBXFileReference section */
148145

149146
/* Begin PBXFrameworksBuildPhase section */
@@ -238,7 +235,6 @@
238235
65744D111C554F0E0011C977 /* SortedMultiSetTests.swift */,
239236
65744D121C554F0E0011C977 /* SortedSetTest.swift */,
240237
65744D131C554F0E0011C977 /* StackTests.swift */,
241-
961E6C3C1DDF9E64004E6C93 /* SampleTests.swift */,
242238
);
243239
path = Tests;
244240
sourceTree = "<group>";
@@ -396,6 +392,7 @@
396392
developmentRegion = English;
397393
hasScannedForEncodings = 0;
398394
knownRegions = (
395+
English,
399396
en,
400397
);
401398
mainGroup = 65744C921C554BA50011C977;
@@ -478,7 +475,6 @@
478475
65744D161C554F0E0011C977 /* DoublyLinkedListTests.swift in Sources */,
479476
65744D1A1C554F0E0011C977 /* QueueTests.swift in Sources */,
480477
65744D1C1C554F0E0011C977 /* RedBlackTreeTests.swift in Sources */,
481-
961E6C3D1DDF9E64004E6C93 /* SampleTests.swift in Sources */,
482478
65744D201C554F0E0011C977 /* SortedMultiDictionaryTests.swift in Sources */,
483479
65744D221C554F0E0011C977 /* SortedMultiSetTests.swift in Sources */,
484480
);
@@ -517,7 +513,6 @@
517513
65744D171C554F0E0011C977 /* DoublyLinkedListTests.swift in Sources */,
518514
65744D1B1C554F0E0011C977 /* QueueTests.swift in Sources */,
519515
65744D1D1C554F0E0011C977 /* RedBlackTreeTests.swift in Sources */,
520-
961E6C3E1DDF9E64004E6C93 /* SampleTests.swift in Sources */,
521516
65744D211C554F0E0011C977 /* SortedMultiDictionaryTests.swift in Sources */,
522517
65744D231C554F0E0011C977 /* SortedMultiSetTests.swift in Sources */,
523518
);

Sources/Algorithm+Array.swift

Lines changed: 124 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -1,145 +1,145 @@
11
/*
2-
* Copyright (C) 2015 - 2018, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.com>.
3-
* All rights reserved.
4-
*
5-
* Redistribution and use in source and binary forms, with or without
6-
* modification, are permitted provided that the following conditions are met:
7-
*
8-
* * Redistributions of source code must retain the above copyright notice, this
9-
* list of conditions and the following disclaimer.
10-
*
11-
* * Redistributions in binary form must reproduce the above copyright notice,
12-
* this list of conditions and the following disclaimer in the documentation
13-
* and/or other materials provided with the distribution.
14-
*
15-
* * Neither the name of CosmicMind nor the names of its
16-
* contributors may be used to endorse or promote products derived from
17-
* this software without specific prior written permission.
18-
*
19-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20-
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22-
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23-
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24-
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25-
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26-
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27-
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28-
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29-
*/
2+
* Copyright (C) 2015 - 2018, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.com>.
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are met:
7+
*
8+
* * Redistributions of source code must retain the above copyright notice, this
9+
* list of conditions and the following disclaimer.
10+
*
11+
* * Redistributions in binary form must reproduce the above copyright notice,
12+
* this list of conditions and the following disclaimer in the documentation
13+
* and/or other materials provided with the distribution.
14+
*
15+
* * Neither the name of CosmicMind nor the names of its
16+
* contributors may be used to endorse or promote products derived from
17+
* this software without specific prior written permission.
18+
*
19+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
*/
3030

3131
extension Array where Element: Equatable {
3232
/**
33-
Removes a given Element from an Array if it exists.
34-
- Parameter object: An Element.
35-
- Returns: An optional Element if the removed
36-
element exists.
37-
*/
38-
@discardableResult
39-
mutating func remove(object: Element) -> Element? {
40-
return index(of: object).map { self.remove(at: $0) }
33+
Removes a given Element from an Array if it exists.
34+
- Parameter object: An Element.
35+
- Returns: An optional Element if the removed
36+
element exists.
37+
*/
38+
@discardableResult
39+
mutating func remove(object: Element) -> Element? {
40+
return index(of: object).map { self.remove(at: $0) }
4141
}
42-
43-
/**
44-
Removes a list of given Elements from an Array if
45-
they exists.
46-
- Parameter objects: A list of Elements.
47-
*/
42+
43+
/**
44+
Removes a list of given Elements from an Array if
45+
they exists.
46+
- Parameter objects: A list of Elements.
47+
*/
4848
mutating func remove(objects: Element...) {
4949
remove(objects: objects)
5050
}
51-
52-
/**
53-
Removes an Array of given Elements from an Array if
54-
they exists.
55-
- Parameter objects: An Array of Elements.
56-
*/
57-
mutating func remove(objects: [Element]) {
58-
objects.forEach {
59-
self.remove(object: $0)
60-
}
51+
52+
/**
53+
Removes an Array of given Elements from an Array if
54+
they exists.
55+
- Parameter objects: An Array of Elements.
56+
*/
57+
mutating func remove(objects: [Element]) {
58+
objects.forEach {
59+
self.remove(object: $0)
60+
}
6161
}
62-
63-
/**
64-
The total count for the given Elements.
65-
- Parameter of elements: A list of Elements.
66-
- Returns: An Int.
67-
*/
62+
63+
/**
64+
The total count for the given Elements.
65+
- Parameter of elements: A list of Elements.
66+
- Returns: An Int.
67+
*/
6868
public func count(of elements: Element...) -> Int {
69-
return count(of: elements)
69+
return count(of: elements)
7070
}
71-
72-
/**
73-
The total count for the given Elements.
74-
- Parameter of elements: An Array of Elements.
75-
- Returns: An Int.
76-
*/
77-
public func count(of elements: [Element]) -> Int {
78-
71+
72+
/**
73+
The total count for the given Elements.
74+
- Parameter of elements: An Array of Elements.
75+
- Returns: An Int.
76+
*/
77+
public func count(of elements: [Element]) -> Int {
78+
7979
var c = 0
80-
for e in elements {
81-
for x in self where e == x {
82-
c += 1
83-
}
84-
}
80+
for e in elements {
81+
for x in self where e == x {
82+
c += 1
83+
}
84+
}
8585
return c
8686
}
87-
88-
/**
89-
The probability of getting the given Elements.
90-
- Parameter of elements: A list of Elements.
91-
- Returns: A Double.
92-
*/
93-
public func probability(of elements: Element...) -> Double {
94-
return probability(of: elements)
87+
88+
/**
89+
The probability of getting the given Elements.
90+
- Parameter of elements: A list of Elements.
91+
- Returns: A Double.
92+
*/
93+
public func probability(of elements: Element...) -> Double {
94+
return probability(of: elements)
9595
}
96-
97-
/**
98-
The probability of getting the given Elements.
99-
- Parameter of elements: An Array of Elements.
100-
- Returns: A Double.
101-
*/
102-
public func probability(of elements: [Element]) -> Double {
103-
return 0 < count ? Double(count(of: elements)) / Double(count) : 0
96+
97+
/**
98+
The probability of getting the given Elements.
99+
- Parameter of elements: An Array of Elements.
100+
- Returns: A Double.
101+
*/
102+
public func probability(of elements: [Element]) -> Double {
103+
return 0 < count ? Double(count(of: elements)) / Double(count) : 0
104104
}
105-
106-
/**
107-
A probability method that uses a block to determine the member state of a condition.
108-
- Parameter of elements: A list of Elements.
109-
- Returns: A Double.
110-
*/
111-
public func probability(execute block: @escaping (Element) -> Bool) -> Double {
112-
guard 0 < count else {
113-
return 0
114-
}
115-
116-
var c = 0
117-
for e in self {
118-
if block(e) {
119-
c += 1
120-
}
121-
}
122-
105+
106+
/**
107+
A probability method that uses a block to determine the member state of a condition.
108+
- Parameter of elements: A list of Elements.
109+
- Returns: A Double.
110+
*/
111+
public func probability(execute block: @escaping (Element) -> Bool) -> Double {
112+
guard 0 < count else {
113+
return 0
114+
}
115+
116+
var c = 0
117+
for e in self {
118+
if block(e) {
119+
c += 1
120+
}
121+
}
122+
123123
return Double(c) / Double(count)
124124
}
125-
126-
/**
127-
Calculates the expected value of elements based on a given number of trials.
128-
- Parameter trials: Number of trials.
129-
- Parameter elements: A list of Elements.
130-
- Returns: A Double.
131-
*/
132-
public func expectedValue(trials: Int, for elements: Element...) -> Double {
133-
return expectedValue(trials: trials, for: elements)
125+
126+
/**
127+
Calculates the expected value of elements based on a given number of trials.
128+
- Parameter trials: Number of trials.
129+
- Parameter elements: A list of Elements.
130+
- Returns: A Double.
131+
*/
132+
public func expectedValue(trials: Int, for elements: Element...) -> Double {
133+
return expectedValue(trials: trials, for: elements)
134134
}
135-
136-
/**
137-
Calculates the expected value of elements based on a given number of trials.
138-
- Parameter trials: Number of trials.
139-
- Parameter elements: An Array of Elements.
140-
- Returns: A Double.
141-
*/
142-
public func expectedValue(trials: Int, for elements: [Element]) -> Double {
143-
return Double(trials) * probability(of: elements)
135+
136+
/**
137+
Calculates the expected value of elements based on a given number of trials.
138+
- Parameter trials: Number of trials.
139+
- Parameter elements: An Array of Elements.
140+
- Returns: A Double.
141+
*/
142+
public func expectedValue(trials: Int, for elements: [Element]) -> Double {
143+
return Double(trials) * probability(of: elements)
144144
}
145145
}

0 commit comments

Comments
 (0)