Chapter 3: Copy on write question

Hi!

I was wondering how it is supposed to work when linked list doesn’t have a references to it (which means that isKnownUniquelyReferenced is true) and we want to remove node after given node?

As far as I can see method copyNodes(returningCopyOf node: Node<Value>?) -> Node<Value>? returns nil if isKnownUniquelyReferenced(&head) is true, which means that first guard in public mutating func remove(after node: Node<Value>) -> Value? is also throws a nil

So I can’t see how removing is going to work when there are no references to the head node.

1 Like