3 ms·
Assuming your hash table is power-of-two sized, could your iterator step forward by (say) 19 elements at a time instead of one? Since 19 is relatively prime to
by panic 10y ago
Assuming your hash table is power-of-two sized, could your iterator step forward by (say) 19 elements at a time instead of one? Since 19 is relatively prime to any power of two, you'll eventually iterate over every element if you take the remainder each time you hit the end. Is there a way to pick the step size to ensure quadratic behavior never happens?
EDIT: The bug description at https://bugs.swift.org/browse/SR-3268 https://bugs.swift.org/browse/SR-3268 mentions this solution but dimisses it due to poor cache locality.