using System.Collections.Generic; namespace Chernobyl.Collections.Generic.Hierarchy { /// /// An type for types that are structured /// like the node on a tree where the type holds a list of it's own type. /// For example: /// /// class Foobar /// { /// public List{Foobar} Children { get; } /// } /// /// This interface also derives from whose /// methods should return the /// iterator best suited for that particular tree whether for speed or /// practicality. /// /// Note to implementors: Chernobyl offers two classes that can help with /// the implementation of an . The /// s and /// allow for iteration over a tree /// composed of types structured like tree nodes in depth and breadth first /// order, respectively. Also, the can /// be used to with the previously mentioned s. /// To add to our Foobar example above, you would extend that class like so: /// /// class Foobar : ITreeEnumerable{Foobar} /// { /// public List{Foobar} Children { get; } /// /// public IEnumerable{Foobar} DepthFirst /// { /// get { return new EnumeratorFactory{Foobar}(() => new DepthFirstEnumerator{Foobar}(this, item => item.Children.GetEnumerator())); } /// } /// /// public IEnumerable{Foobar} BreadthFirst /// { /// get { return new EnumeratorFactory{Foobar}(() => new BreadthFirstEnumerator{Foobar}(this, item => item.Children.GetEnumerator())); } /// } /// /// public IEnumerator{T} GetEnumerator() /// { /// return DepthFirst.GetEnumerator(); /// } /// /// IEnumerator IEnumerable.GetEnumerator() /// { /// return GetEnumerator(); /// } /// } /// /// /// /// The type that is structured like the node of a tree. public interface ITreeEnumerable : IEnumerable { /// /// An that iterates over an /// in depth first order (see /// http://en.wikipedia.org/wiki/Depth-first_search for more information). /// IEnumerable DepthFirst { get; } /// /// An that iterates over an /// in breadth first order (see /// http://en.wikipedia.org/wiki/Breadth-first_search for more information). /// IEnumerable BreadthFirst { get; } } }