TIL about faster `Array` operations with `CollectionOfOne` in Swift
Read Faster Array
Operations With CollectionOfOne
in Swift. Nothing new. Side learning: i..<i
is valid range. Empty one.
Looking at implementation of insert(_:, at:)
I am thinking if would it be more effective to add specialised version for replacing subrange with single element instead of creating CollectionOfOne
:
public mutating func insert(_ newElement: __owned Element, at i: Int) {
_checkIndex(i)
self.replaceSubrange(i..<i, with: CollectionOfOne(newElement))
}
Passed the first week of Coursera’s Introduction to TensorFlow for Artificial Intelligence, Machine Learning, and Deep Learning.