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.

Published 05 October 04 02:53 by GarethJ
Filed under:

Comments

No Comments
New Comments to this post are disabled

Search

This Blog

Disclaimer
The information in this weblog is provided "AS IS" with no warranties, and confers no rights. This weblog does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my opinion. Inappropriate comments will be deleted at the authors discretion.
All code samples are provided "AS IS" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.

Tags

Archives

Architects who Model

DSL Tools Team

Links

Syndication

Page view tracker