Example #1
0
        /// <summary>Returns all sub-trees enumerated from left to right.</summary>
        /// <returns>Enumerated sub-trees or empty if tree is empty.</returns>
        public IEnumerable <ImTreeMapIntToObj> Enumerate()
        {
            if (Height == 0)
            {
                yield break;
            }

            var parents = new ImTreeMapIntToObj[Height];

            var tree        = this;
            var parentCount = -1;

            while (tree.Height != 0 || parentCount != -1)
            {
                if (tree.Height != 0)
                {
                    parents[++parentCount] = tree;
                    tree = tree.Left;
                }
                else
                {
                    tree = parents[parentCount--];
                    yield return(tree);

                    tree = tree.Right;
                }
            }
        }
Example #2
0
 private ImTreeMapIntToObj(int key, object value, ImTreeMapIntToObj left, ImTreeMapIntToObj right)
 {
     Key    = key;
     Value  = value;
     Left   = left;
     Right  = right;
     Height = 1 + (left.Height > right.Height ? left.Height : right.Height);
 }
Example #3
0
 private ImTreeMapIntToObj With(ImTreeMapIntToObj left, ImTreeMapIntToObj right)
 {
     return(left == Left && right == Right ? this : new ImTreeMapIntToObj(Key, Value, left, right));
 }