Skip to content

Commit 70781ec

Browse files
committed
Remove needless self references to follow the repository's Swift style guidelines.
1 parent 74fb0ec commit 70781ec

File tree

1 file changed

+48
-48
lines changed

1 file changed

+48
-48
lines changed

Singly Linked List/SinglyLinkedList.swift

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,17 @@ public struct SinglyLinkedList<T>
6565
private var storageForWritting: IndirectStorage<T> {
6666

6767
mutating get {
68-
if !isKnownUniquelyReferenced(&self.storage) {
69-
self.storage = self.copyStorage()
68+
if !isKnownUniquelyReferenced(&storage) {
69+
storage = copyStorage()
7070
}
71-
return self.storage
71+
return storage
7272
}
7373
}
7474

7575
/// Returns the last element in the collection
7676
public var last: T? {
7777
get {
78-
return self.storage.tail?.value
78+
return storage.tail?.value
7979
}
8080
}
8181

@@ -108,7 +108,7 @@ public struct SinglyLinkedList<T>
108108
public mutating func append(value: T)
109109
{
110110
let node = SinglyLinkedListNode<T>(value: value)
111-
self.append(node: node)
111+
append(node: node)
112112
}
113113

114114

@@ -118,16 +118,16 @@ public struct SinglyLinkedList<T>
118118
public mutating func prepend(value: T)
119119
{
120120
let node = SinglyLinkedListNode<T>(value: value)
121-
self.prepend(node: node)
121+
prepend(node: node)
122122
}
123123

124124

125125
public mutating func deleteItem(at index:Int) -> T
126126
{
127-
precondition((index >= 0) && (index < self.count))
127+
precondition((index >= 0) && (index < count))
128128

129129
var previous: SinglyLinkedListNode<T>? = nil
130-
var current = self.storageForWritting.head
130+
var current = storageForWritting.head
131131
var i = 0
132132
var elementToDelete: SinglyLinkedListNode<T>
133133

@@ -139,12 +139,12 @@ public struct SinglyLinkedList<T>
139139

140140
// Current is now the element to delete (at index position.tag)
141141
elementToDelete = current!
142-
if (self.storage.head === current) {
143-
self.storageForWritting.head = current?.next
142+
if (storage.head === current) {
143+
storageForWritting.head = current?.next
144144
}
145145

146-
if (self.storage.tail === current) {
147-
self.storageForWritting.tail = previous
146+
if (storage.tail === current) {
147+
storageForWritting.tail = previous
148148
}
149149

150150
previous?.next = current?.next
@@ -184,7 +184,7 @@ public struct SinglyLinkedList<T>
184184
/// - Parameter kthToLast: Reversed ordinal number of the node to fetch.
185185
public func find(kthToLast: UInt) -> SinglyLinkedListNode<T>?
186186
{
187-
return self.find(kthToLast: kthToLast, startingAt: self.storage.head, count: UInt(self.count))
187+
return find(kthToLast: kthToLast, startingAt: storage.head, count: UInt(count))
188188
}
189189

190190
}
@@ -202,11 +202,11 @@ private extension SinglyLinkedList {
202202
private mutating func prepend(node: SinglyLinkedListNode<T>)
203203
{
204204
let (tailFromNewNode, _) = findTail(in: node)
205-
tailFromNewNode.next = self.storageForWritting.head
206-
self.storageForWritting.head = node
205+
tailFromNewNode.next = storageForWritting.head
206+
storageForWritting.head = node
207207

208-
if self.storage.tail == nil {
209-
self.storageForWritting.tail = tailFromNewNode
208+
if storage.tail == nil {
209+
storageForWritting.tail = tailFromNewNode
210210
}
211211
}
212212

@@ -217,22 +217,22 @@ private extension SinglyLinkedList {
217217
/// - Parameter node: node to be appended. (It can be a list, even contain loops).
218218
private mutating func append(node: SinglyLinkedListNode<T>)
219219
{
220-
if self.storage.tail != nil
220+
if storage.tail != nil
221221
{
222222
// Copy on write: we are about to modify next a property in
223223
// a potentially shared node. Make sure it's new if necessary.
224-
self.storageForWritting.tail?.next = node
224+
storageForWritting.tail?.next = node
225225
let (tail, _) = findTail(in: node)
226-
self.storageForWritting.tail = tail // There
226+
storageForWritting.tail = tail // There
227227
}
228228
else
229229
{
230230
// This also means that there's no head.
231231
// Otherwise the state would be inconsistent.
232232
// This will be checked when adding and deleting nodes.
233-
self.storageForWritting.head = node
233+
storageForWritting.head = node
234234
let (tail, _) = findTail(in: node)
235-
self.storageForWritting.tail = tail // There
235+
storageForWritting.tail = tail // There
236236
}
237237
}
238238

@@ -243,18 +243,18 @@ private extension SinglyLinkedList {
243243
// If the list is empty, next time an item will be created, it won't affect
244244
// other instances of the list that came from copies derived from value types.
245245
// like assignments or parameters
246-
guard (self.storage.head != nil) && (self.storage.tail != nil) else {
246+
guard (storage.head != nil) && (storage.tail != nil) else {
247247
return IndirectStorage(head: nil, tail: nil)
248248
}
249249

250250
// Create a new position in memory.
251251
// Note that we are shallow copying the value. If it was reference type
252252
// we just make a copy of the reference.
253-
let copiedHead = SinglyLinkedListNode<T>(value: self.storage.head!.value)
253+
let copiedHead = SinglyLinkedListNode<T>(value: storage.head!.value)
254254
var previousCopied: SinglyLinkedListNode<T> = copiedHead
255255

256256
// Iterate through current list of nodes and copy them.
257-
var current: SinglyLinkedListNode<T>? = self.storage.head?.next
257+
var current: SinglyLinkedListNode<T>? = storage.head?.next
258258

259259
while (current != nil) {
260260
// Create a copy
@@ -283,12 +283,12 @@ extension SinglyLinkedList where T: Comparable
283283
/// - Parameter v: value of the node to be deleted.
284284
public mutating func deleteNode(withValue v: T) {
285285

286-
guard self.storage.head != nil else {
286+
guard storage.head != nil else {
287287
return
288288
}
289289

290290
var previous: SinglyLinkedListNode<T>? = nil
291-
var current = self.storage.head
291+
var current = storage.head
292292

293293
while (current != nil) && (current?.value != v) {
294294
previous = current
@@ -297,12 +297,12 @@ extension SinglyLinkedList where T: Comparable
297297

298298
if let foundNode = current {
299299

300-
if (self.storage.head === foundNode) {
301-
self.storageForWritting.head = foundNode.next
300+
if (storage.head === foundNode) {
301+
storageForWritting.head = foundNode.next
302302
}
303303

304-
if (self.storage.tail === foundNode) {
305-
self.storage.tail = previous
304+
if (storage.tail === foundNode) {
305+
storage.tail = previous
306306
}
307307

308308
previous?.next = foundNode.next
@@ -315,8 +315,8 @@ extension SinglyLinkedList where T: Comparable
315315
/// - Complexity: O(N^2)
316316
public mutating func deleteDuplicatesInPlace()
317317
{
318-
// Copy on write: this updates self.storage if necessary.
319-
var current = self.storageForWritting.head
318+
// Copy on write: this updates storage if necessary.
319+
var current = storageForWritting.head
320320

321321
while (current != nil)
322322
{
@@ -327,12 +327,12 @@ extension SinglyLinkedList where T: Comparable
327327
{
328328
if (current?.value == next?.value) {
329329

330-
if (self.storage.head === next) {
331-
self.storage.head = next?.next
330+
if (storage.head === next) {
331+
storage.head = next?.next
332332
}
333333

334-
if (self.storage.tail === next) {
335-
self.storage.tail = previous
334+
if (storage.tail === next) {
335+
storage.tail = previous
336336
}
337337

338338
// Delete next
@@ -358,8 +358,8 @@ public struct SinglyLinkedListForwardIterator<T> : IteratorProtocol {
358358

359359
mutating public func next() -> T?
360360
{
361-
let result = self.head?.value
362-
self.head = self.head?.next
361+
let result = head?.value
362+
head = head?.next
363363
return result
364364
}
365365
}
@@ -372,7 +372,7 @@ extension SinglyLinkedList : Sequence
372372
{
373373
public func makeIterator() -> SinglyLinkedListForwardIterator<T>
374374
{
375-
return SinglyLinkedListForwardIterator(head: self.storage.head)
375+
return SinglyLinkedListForwardIterator(head: storage.head)
376376
}
377377
}
378378

@@ -386,17 +386,17 @@ extension SinglyLinkedList : Collection {
386386

387387
public var startIndex: Index {
388388
get {
389-
return SinglyLinkedListIndex<T>(node: self.storage.head, tag: 0)
389+
return SinglyLinkedListIndex<T>(node: storage.head, tag: 0)
390390
}
391391
}
392392

393393
public var endIndex: Index {
394394
get {
395-
if let h = self.storage.head {
395+
if let h = storage.head {
396396
let (_, numberOfElements) = findTail(in: h)
397397
return SinglyLinkedListIndex<T>(node: h, tag: numberOfElements)
398398
} else {
399-
return SinglyLinkedListIndex<T>(node: nil, tag: self.startIndex.tag)
399+
return SinglyLinkedListIndex<T>(node: nil, tag: startIndex.tag)
400400
}
401401
}
402402
}
@@ -425,23 +425,23 @@ extension SinglyLinkedList : ExpressibleByArrayLiteral
425425
var headSet = false
426426
var current : SinglyLinkedListNode<T>?
427427
var numberOfElements = 0
428-
self.storage = IndirectStorage()
428+
storage = IndirectStorage()
429429

430430
for element in elements {
431431

432432
numberOfElements += 1
433433

434434
if headSet == false {
435-
self.storage.head = SinglyLinkedListNode<T>(value: element)
436-
current = self.storage.head
435+
storage.head = SinglyLinkedListNode<T>(value: element)
436+
current = storage.head
437437
headSet = true
438438
} else {
439439
let newNode = SinglyLinkedListNode<T>(value: element)
440440
current?.next = newNode
441441
current = newNode
442442
}
443443
}
444-
self.storage.tail = current
444+
storage.tail = current
445445
}
446446
}
447447

@@ -467,7 +467,7 @@ public struct SinglyLinkedListIndex<T> : Comparable
467467
extension SinglyLinkedList where T : KeyValuePair {
468468

469469
public func find(elementWithKey key: T.K) -> T? {
470-
let searchResults = self.filter { (keyValuePair) -> Bool in
470+
let searchResults = filter { (keyValuePair) -> Bool in
471471
return keyValuePair.key == key
472472
}
473473

0 commit comments

Comments
 (0)