How to check two `Array` instances for identity equality in constant time?

It depends on context. Suppose I have a function:

func foo<T>(_: [T]) { … }

In general, the running time of foo() will depend on two parameters: the size of T, and the number of elements in the array. If we fix either parameter while letting the other vary, we may observe very different behaviors, for example the algorithm might be linear in the size of T but quadratic in the length of the array.

That is correct. Copying or moving a Swift value will in general require a number of steps that is linear in the size of the value.

5 Likes