I am doing a performance-critical program (few academic materials), and I try to optimize it wherever possible (not as "this" bottleneck was proven).
I have a custom dictionary structure (wrapper around the .NET Dictionary<,> ), and I would constantly delete elements at one stage (by Key value). I need Value deleted items. Now I have to do:
T t; if !TryGet(key, out t) return false; Remove(key);
These are two searches. I would like it:
public bool Remove(S key, out T value) {
I know that there is nothing in the framework, but is there an implementation somewhere? If so, I would change my maintenance dictionary with this.
Edit: I know that both TryGetValue and Remove are O (1). Just knowing if there is any collection structure that will give the same effect in only one search. As I said, I try to optimize as much as possible. Just knowing.
source share