rewritten erase(key) to avoid implicit iterator increments leading to linear complexity, as reported by Guillaume Lazzara