Delegate methods on the Heap class

I shamelessly copied the delegate methods on my heap class from those on List. Delegate methods provide a step on the way towards enabling a separation in the collections programming model between structure and algorithm. You might express this as "what shape is a heap?" and "what operations can I perform across any data structure?"
Its not STL yet, but its a start.

You can find some more detail and examples of the functions here, but here is a very basic example of the sort of stuff you can do with a combination of these delegate methods and the C# 2.0 anonymous delegates feature:

Heap subHeap = aHeap.FindAll(delegate(string val) { return (val == null ? "" : val).StartsWith("Fred"); });

This creates a subset of a heap containing all the entries which started with the string "Fred".
If you then start to factor in the full closure power of anonymous delegates, (allowing you to use data from calling functions seamlessly in operations across your collections), you get a pretty strong programming model.
See Martin Fowler for more information on why closures are good things.

Skip to main content