fix node removal

This commit is contained in:
Sami Samhuri 2016-08-11 18:39:56 -07:00
parent fe4dc9a69a
commit 45538b940c
2 changed files with 6 additions and 9 deletions

View file

@ -58,18 +58,15 @@ struct DoublyLinkedList {
} }
mutating func remove(node node: Node) { mutating func remove(node node: Node) {
if let prev = node.prev { if node === head {
prev.next = node.next
}
else {
head = node.next head = node.next
} }
if let next = node.next { if node === tail {
next.prev = node.prev
}
else {
tail = node.prev tail = node.prev
} }
node.prev?.next = node.next
node.next?.prev = node.prev
node.next = nil node.next = nil
node.prev = nil node.prev = nil
count -= 1 count -= 1

View file

@ -7,7 +7,7 @@
// Modified to use LRU eviction by Sami Samhuri on 2016-08-10. // Modified to use LRU eviction by Sami Samhuri on 2016-08-10.
// //
import Foundation import UIKit
/// `LRUCache` is an LRU cache that can hold anything, including Swift structs, enums, and values. /// `LRUCache` is an LRU cache that can hold anything, including Swift structs, enums, and values.
/// It is designed to work similar to the `NSCache`, but with native Swift support. /// It is designed to work similar to the `NSCache`, but with native Swift support.