KeRNeLith / QuikGraph

Generic Graph Data Structures and Algorithms for .NET
https://kernelith.github.io/QuikGraph/
Microsoft Public License
467 stars 69 forks source link

[FEATURE] Add `Clear()` to collection types #78

Open jnyrup opened 1 year ago

jnyrup commented 1 year ago

Is your feature request related to a problem? Please describe. When wanting to clear e.g. a FibonacciQueue there is as far as I can see no efficient way to do this.

An inefficient way is to repeatedly call dequeue until it is empty, but that causes unnecessary updates of the data structure to maintain the invariants for each call to Dequeue.

while (queue.Count > 0) // Dispose all calculation items
{
    _ = queue.Dequeue();
}

Describe the solution you'd like BCL collection types like List<T> and Dictionary<TKey, TValue> have a Clear() method to empty them. It would be nice for all/most QuikGraph collections to have a similar method.

The ones I have seen missing a Clear are:

If acceptable IQueue<T> and IDisjointSet<T> could have a void Clear() added, but that is technically a breaking change if any consumers have already implemented those interfaces.

Describe alternatives you've considered

Additional context I'd be happy to do the implementation and testing of this.