c# - Performance of nested yield in a tree -


I have a tree-like structure, each element of this structure should be able to calculate all the elements that it is root . Let's call this method IEnumerable & lt; Foo & gt; GetAll () . So if we have

  a < - Top Root / \ BC / \ / DEFG  

call GetAll element returns {C, F, G} } (the exact order of elements will be good, but this is not required). I think everyone knows that already.

The current implementation of GetAll looks like this:

  public IEnumerable & lt; Foo & gt; GetAll () returns yield; Foreign (Fu Fu in My Childhood) {in foreach (foo.foo.GetAll ()) F (F) returns F; }}}  

In the previous implementation, I returned a list and hair-fuzz was List.AddRange () . Added by using .

My question is whether the version has been implemented correctly using the yield or if it should be improved (especially in the case of performance) or it is simply bad and I instead use list < Want to stick to / code> s (or ReadOnlyCollections )?

This is certainly not ideal in terms of performance - you are not ideal for large trees instead of the same iterator. There are lots of itators to create, who know how to skillfully cross.

Some blog entries related to this:

  • Wes Dyer:
  • Eric Liebert:
  • Eric again: Li>

It is worth noting that F # has the " yield! "


Comments

Popular posts from this blog

c++ - Linux and clipboard -

Visual Studio 2005: How to speed up builds when a VSMDI is open? -

booting ubuntu from usb using virtualbox -