Skip to content

Commit 6da482c

Browse files
committed
General file cleanup..
1 parent ef8bc31 commit 6da482c

File tree

11 files changed

+65
-216
lines changed

11 files changed

+65
-216
lines changed

Source/Extensions/Array.swift

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,39 @@ import Foundation
1111

1212
extension Array where Element: Comparable {
1313

14+
15+
//determines the longest sequence of specified values
16+
func longestSequence(of key: Element) -> Int {
17+
18+
//initial values
19+
var current: Element
20+
var counter: Int = 0
21+
var longest: Int = 0
22+
23+
//iterate through list - O(n)
24+
for s in self {
25+
26+
//current iteration
27+
current = s
28+
29+
if current == key {
30+
counter += 1
31+
}
32+
else {
33+
counter = 0
34+
}
35+
36+
//preserve the longest sequence
37+
if counter >= longest {
38+
longest = counter
39+
}
40+
}
41+
42+
//return count results
43+
return longest
44+
45+
}
46+
1447

1548
//MARK: Index Operation
1649

Source/Extensions/Chain.swift

Lines changed: 11 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@ extension Blockchain {
1717

1818
let newblock = Block()
1919

20+
/*
21+
not required as all these properties are optional..
2022
newblock.key = nil
2123
newblock.miner = nil
2224
newblock.previous = nil
2325
newblock.transactions = nil
26+
*/
27+
2428
newblock.description = "Genesis Block"
2529

2630
return newblock
@@ -39,54 +43,16 @@ extension Blockchain {
3943
}
4044

4145

42-
//TODO: estblish new block based on provided input and the level of difficulty.
43-
func hashValue(_ element: Block) -> Hash? {
44-
45-
var rawvalue = Int()
46-
var leadvalue = Int()
47-
48-
49-
//check tranactions
50-
guard let items = element.transactions else {
51-
return nil
52-
}
53-
46+
func puzzle(newBlock: Block) -> Hash? {
47+
48+
return nil
5449

55-
//sum hash values
56-
for exchange in items {
57-
rawvalue = exchange.amount.hashValue
58-
rawvalue += exchange.from.hashValue
59-
rawvalue += exchange.to.hashValue
60-
rawvalue += exchange.lastModified.hashValue
61-
}
62-
50+
//takes the value, converts it to a string array, send the 4 leading characters "array slice" to the closure, have it
51+
//calculate the result. The closure results determines of the puzzle should repeat.
6352

64-
//sum previous hash
65-
if let previous = element.previous {
66-
rawvalue += previous.hashValue
67-
}
68-
69-
70-
while leadvalue >= difficulty {
71-
72-
print("mining new block..")
73-
let testvalue = rawvalue + String(describing: Date()).hashValue
74-
75-
let rawlist: Array<Int> = String(testvalue).characters.flatMap{Int(String($0))}
76-
77-
for m in 0..<rawlist.startIndex + 3 {
78-
leadvalue += rawlist[m]
79-
}
80-
81-
//perform final bit shift and test leading values
82-
if (leadvalue >> 2) >= difficulty {
83-
return String(testvalue)
84-
}
85-
86-
}
53+
//the new hash is just a combination of the previous hash combined with the hash of the
54+
//previous transactions along with the date..
8755

88-
return nil
89-
9056
}
9157

9258

Source/Extensions/Int.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ extension Int: Keyable {
2525
}
2626
}
2727

28-
28+
2929

3030
//build fibonacci sequence to a specified position - default
3131
func fibNormal() -> Array<Int>? {
@@ -133,7 +133,7 @@ extension Int: Keyable {
133133
*/
134134

135135
//calculate results
136-
mutating func fibMemoized() -> Int {
136+
func fibMemoized() -> Int {
137137

138138

139139
//builds array sequence

Source/Extensions/String.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ extension String: Keyable {
2222
var length: Int {
2323
return self.count
2424
}
25+
26+
2527

2628

2729
//determine if all characters are unique

Source/Factories/Blockchain.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public class Blockchain: Graph {
6161

6262
let queue = network.queue
6363
let threshold = network.threshold
64-
let chain = network.chain
64+
//let chain = network.chain
6565

6666

6767
for exchange in peer.intentions {
@@ -99,7 +99,7 @@ public class Blockchain: Graph {
9999

100100
private func newBlock(for network: Blockchain) -> Bool {
101101

102-
//esablish queue
102+
//establish queue
103103
let queue = network.queue
104104
let newblock = Block()
105105
var transactions = Array<Exchange>()
@@ -124,7 +124,7 @@ public class Blockchain: Graph {
124124
newblock.miner = self
125125
newblock.previous = network.currentBlock().key
126126
newblock.transactions = transactions
127-
newblock.key = network.hashValue(newblock)
127+
//newblock.key = network.hashValue(newblock)
128128

129129
/*
130130
note: This is also where the hash algorithm for each block obtained. For clarity, make the

Source/Factories/LinkedList.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,6 @@ class LinkedList<T> {
293293

294294
}
295295

296-
297296

298297

299298
//MARK: Closure operations
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>

SwiftStructures.xcodeproj/xcuserdata/waynebishop.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

Lines changed: 0 additions & 161 deletions
Original file line numberDiff line numberDiff line change
@@ -2,165 +2,4 @@
22
<Bucket
33
type = "1"
44
version = "2.0">
5-
<Breakpoints>
6-
<BreakpointProxy
7-
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
8-
<BreakpointContent
9-
shouldBeEnabled = "No"
10-
ignoreCount = "0"
11-
continueAfterRunningActions = "No"
12-
filePath = "SwiftTests/HashTest.swift"
13-
timestampString = "543522989.152511"
14-
startingColumnNumber = "9223372036854775807"
15-
endingColumnNumber = "9223372036854775807"
16-
startingLineNumber = "79"
17-
endingLineNumber = "79"
18-
landmarkName = "testMissingList()"
19-
landmarkType = "7">
20-
<Locations>
21-
<Location
22-
shouldBeEnabled = "No"
23-
ignoreCount = "0"
24-
continueAfterRunningActions = "No"
25-
symbolName = "SwiftTests.HashTest.testMissingList() -&gt; ()"
26-
moduleName = "SwiftTests"
27-
usesParentBreakpointCondition = "Yes"
28-
urlString = "file:///Users/waynebishop/Dropbox/iPhone%20Development/SwiftStructures/SwiftTests/HashTest.swift"
29-
timestampString = "533859967.12933"
30-
startingColumnNumber = "9223372036854775807"
31-
endingColumnNumber = "9223372036854775807"
32-
startingLineNumber = "79"
33-
endingLineNumber = "79"
34-
offsetFromSymbolStart = "131">
35-
</Location>
36-
<Location
37-
shouldBeEnabled = "No"
38-
ignoreCount = "0"
39-
continueAfterRunningActions = "No"
40-
symbolName = "implicit closure #1 : @autoclosure () throws -&gt; Swift.Bool in SwiftTests.HashTest.testMissingList() -&gt; ()"
41-
moduleName = "SwiftTests"
42-
usesParentBreakpointCondition = "Yes"
43-
urlString = "file:///Users/waynebishop/Dropbox/iPhone%20Development/SwiftStructures/SwiftTests/HashTest.swift"
44-
timestampString = "533859967.132433"
45-
startingColumnNumber = "9223372036854775807"
46-
endingColumnNumber = "9223372036854775807"
47-
startingLineNumber = "79"
48-
endingLineNumber = "79"
49-
offsetFromSymbolStart = "14">
50-
</Location>
51-
<Location
52-
shouldBeEnabled = "No"
53-
ignoreCount = "0"
54-
continueAfterRunningActions = "No"
55-
symbolName = "implicit closure #2 : @autoclosure () -&gt; Swift.String in SwiftTests.HashTest.testMissingList() -&gt; ()"
56-
moduleName = "SwiftTests"
57-
usesParentBreakpointCondition = "Yes"
58-
urlString = "file:///Users/waynebishop/Dropbox/iPhone%20Development/SwiftStructures/SwiftTests/HashTest.swift"
59-
timestampString = "533859967.135077"
60-
startingColumnNumber = "9223372036854775807"
61-
endingColumnNumber = "9223372036854775807"
62-
startingLineNumber = "79"
63-
endingLineNumber = "79"
64-
offsetFromSymbolStart = "4">
65-
</Location>
66-
</Locations>
67-
</BreakpointContent>
68-
</BreakpointProxy>
69-
<BreakpointProxy
70-
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
71-
<BreakpointContent
72-
shouldBeEnabled = "No"
73-
ignoreCount = "0"
74-
continueAfterRunningActions = "No"
75-
filePath = "Source/Factories/BSTree.swift"
76-
timestampString = "533860009.986163"
77-
startingColumnNumber = "9223372036854775807"
78-
endingColumnNumber = "9223372036854775807"
79-
startingLineNumber = "43"
80-
endingLineNumber = "43"
81-
landmarkName = "append(element:)"
82-
landmarkType = "7">
83-
</BreakpointContent>
84-
</BreakpointProxy>
85-
<BreakpointProxy
86-
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
87-
<BreakpointContent
88-
shouldBeEnabled = "No"
89-
ignoreCount = "0"
90-
continueAfterRunningActions = "No"
91-
filePath = "Source/Factories/BSTree.swift"
92-
timestampString = "533860009.986865"
93-
startingColumnNumber = "9223372036854775807"
94-
endingColumnNumber = "9223372036854775807"
95-
startingLineNumber = "139"
96-
endingLineNumber = "139"
97-
landmarkName = "push(element:)"
98-
landmarkType = "7">
99-
</BreakpointContent>
100-
</BreakpointProxy>
101-
<BreakpointProxy
102-
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
103-
<BreakpointContent
104-
shouldBeEnabled = "No"
105-
ignoreCount = "0"
106-
continueAfterRunningActions = "No"
107-
filePath = "Source/Extensions/Int.swift"
108-
timestampString = "535328261.598035"
109-
startingColumnNumber = "9223372036854775807"
110-
endingColumnNumber = "9223372036854775807"
111-
startingLineNumber = "25"
112-
endingLineNumber = "25"
113-
landmarkName = "times(closure:)"
114-
landmarkType = "7">
115-
</BreakpointContent>
116-
</BreakpointProxy>
117-
<BreakpointProxy
118-
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
119-
<BreakpointContent
120-
shouldBeEnabled = "Yes"
121-
ignoreCount = "0"
122-
continueAfterRunningActions = "No"
123-
filePath = "SwiftTests/FibTest.swift"
124-
timestampString = "540942274.158419"
125-
startingColumnNumber = "9223372036854775807"
126-
endingColumnNumber = "9223372036854775807"
127-
startingLineNumber = "50"
128-
endingLineNumber = "50"
129-
landmarkName = "testFibRecursive()"
130-
landmarkType = "7">
131-
</BreakpointContent>
132-
</BreakpointProxy>
133-
<BreakpointProxy
134-
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
135-
<BreakpointContent
136-
shouldBeEnabled = "Yes"
137-
ignoreCount = "0"
138-
continueAfterRunningActions = "No"
139-
filePath = "SwiftTests/SortingTest.swift"
140-
timestampString = "543524921.796223"
141-
startingColumnNumber = "9223372036854775807"
142-
endingColumnNumber = "9223372036854775807"
143-
startingLineNumber = "44"
144-
endingLineNumber = "44"
145-
landmarkName = "testUniqueEssayExample()"
146-
landmarkType = "7">
147-
</BreakpointContent>
148-
</BreakpointProxy>
149-
<BreakpointProxy
150-
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
151-
<BreakpointContent
152-
shouldBeEnabled = "Yes"
153-
ignoreCount = "0"
154-
continueAfterRunningActions = "No"
155-
filePath = "SwiftTests/BlockTest.swift"
156-
timestampString = "543816078.602953"
157-
startingColumnNumber = "9223372036854775807"
158-
endingColumnNumber = "9223372036854775807"
159-
startingLineNumber = "54"
160-
endingLineNumber = "54"
161-
landmarkName = "testMiningBlock()"
162-
landmarkType = "7">
163-
</BreakpointContent>
164-
</BreakpointProxy>
165-
</Breakpoints>
1665
</Bucket>

SwiftTests/FibTest.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class FibTest: XCTestCase {
9797

9898
func testFibMemoized() {
9999

100-
var positions: Int = 4
100+
let positions: Int = 4
101101
let result = positions.fibMemoized()
102102

103103
//test trivial condition

SwiftTests/SortingTest.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,12 @@ class SortingTest: XCTestCase, Sortable {
3838
super.setUp()
3939
}
4040

41-
func testUniqueEssayExample(){
41+
func testLongestSequence() {
4242

43-
let results = "Uncopyrightable".isStringUnique()
43+
let list = [0,1,0,1,1,1,0,1,1,1,1,1]
44+
let results = list.longestSequence(of: 1)
45+
46+
print("the longest sequence is \(results)")
4447
}
4548

4649

@@ -97,7 +100,6 @@ class SortingTest: XCTestCase, Sortable {
97100
XCTAssertTrue(isSorted(triviaTextList.insertionSort()))
98101
XCTAssertTrue(isSorted(emptyTextList.insertionSort()))
99102
XCTAssert(isSorted(dateList.insertionSort()))
100-
101103
}
102104

103105

0 commit comments

Comments
 (0)