Re: Calling fire and forget methods.

Davy J <[email protected]> Tue, 26 Feb 2008 14:28:35 +0100
Newsgroups gmane.comp.windows.devel.dotnet.clr
Message-ID <[email protected]>
Thanks all,

  case of couldn't see the wood for the trees there.  for info  I don't know
if the tree will be balanced or not, so the array implementation wouldn't
fit.

  Here's the finished method,  shaves 10 seconds off of my previous best
try.


       internal void Add(T newItem)
        {
            if (this.value == null) //Short cut for the first pass.
            {
                this.value = newItem;
                this.valueComparer = (IComparable)pi.GetValue(value, null);
                return;
            }


            TreeNode<T> parent = this;      //set up our point to the
current node we're checking
            IComparable newObject = (IComparable)pi.GetValue(newItem, null);
//Get an IComparable for property to sort by
            while (true)    //we exit with a break.
            {
                if(parent.value == null){   //we've found an empty base
object, fill it in
                    parent.value = newItem;
                    parent.valueComparer = newObject; //Pass our IComparable
to save time.
                    break;  //the real exit to the while.
                }
                //if the parent value is bigger than the new object.
                if (parent.valueComparer.CompareTo(newObject) > 0)
                {
                    //Add it to our left side.
                    if (parent.leftNode == null)
                    {
                        parent.leftNode = new TreeNode<T>(pi);  //Add the
left node
                    }
                    parent = parent.leftNode; //Move our pointer
                }
                else
                {
                    if (parent.rightNode == null)   //It's either the same
or bigger than our parent
                    {
                        parent.rightNode = new TreeNode<T>(pi); //No node to
fill? add one.
                    }
                    parent = parent.rightNode;  //Move our pointer
                }
            }
        }

===================================
This list is hosted by DevelopMentor®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com