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) {
if let prev = node.prev {
prev.next = node.next
}
else {
if node === head {
head = node.next
}
if let next = node.next {
next.prev = node.prev
}
else {
if node === tail {
tail = node.prev
}
node.prev?.next = node.next
node.next?.prev = node.prev
node.next = nil
node.prev = nil
count -= 1

View file

@ -7,7 +7,7 @@
// 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.
/// It is designed to work similar to the `NSCache`, but with native Swift support.