In the implementation for the dequeue
method, there is a check made for the total elements in the array and the percentage
? What is this used for?
public mutating func dequeue() -> T? {
guard head < array.count,
let element = array[head] else {
return nil
}
array[head] = nil
head += 1
let percentage = Double(head)/Double(array.count) // What is this doing?
if array.count > 50, // What's different between having 40 or 60 elements?
percentage > 0.25 { // Is this necessary? We already have an element
array.removeFirst()
head = 0
}
return element
}