Skip to content

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

@jnyrup

Description

@jnyrup

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:

  • BinaryQueue, BinaryQueue,
  • FibonacciQueue, FibonacciHeap, FibonacciHeapLinkedList
  • ForestDisjointSet

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.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions