Tests/IMToolsTests.cs
/// <summary>
/// Returns all map tree nodes enumerated from the lesser to the bigger keys
/// </summary>
Returns all map tree nodes enumerated from the lesser to the bigger keys
Returns all map tree nodes enumerated from the lesser to the bigger keys
public IEnumerable<ImMap<V>> Enumerate(ImMap<V>[] parentStack = null)
        {
            if (Height == 0)
                yield break;
            if (Height == 1)
            {
                yield return this;
            }
            else if (Height == 2)
            {
                if (Left.Height != 0)
                    yield return Left;
                yield return this;
                if (Right.Height != 0)
                    yield return Right;
            }
            else
            {
                parentStack = parentStack ?? new ImMap<V>[Height - 2];
                var map = this;
                var parentIndex = -1;
                while (map.Height != 0)
                {
                    if (map.Height == 1)
                    {
                        yield return map;
                        if (parentIndex == -1)
                            break;
                        yield return map = parentStack[parentIndex--];
                        map = map.Right;
                    }
                    else if (map.Height == 2)
                    {
                        if (map.Left.Height != 0)
                            yield return map.Left;
                        yield return map;
                        if (map.Right.Height != 0)
                            yield return map.Right;
                        if (parentIndex == -1)
                            break;
                        yield return map = parentStack[parentIndex--];
                        map = map.Right;
                    }
                    else
                    {
                        parentStack[++parentIndex] = map;
                        map = map.Left;
                    }
                }
            }
        }
public IEnumerable < ImMap < V > > Enumerate ( ImMap < V > [ ] parentStack = null ) { if ( Height == 0 ) yield break ; if ( Height == 1 ) { yield return this ; } else if ( Height == 2 ) { if ( Left . Height != 0 ) yield return Left ; yield return this ; if ( Right . Height != 0 ) yield return Right ; } else { parentStack = parentStack ?? new ImMap < V > [ Height - 2 ] ; var map = this ; var parentIndex = - 1 ; while ( map . Height != 0 ) { if ( map . Height == 1 ) { yield return map ; if ( parentIndex == - 1 ) break ; yield return map = parentStack [ parentIndex -- ] ; map = map . Right ; } else if ( map . Height == 2 ) { if ( map . Left . Height != 0 ) yield return map . Left ; yield return map ; if ( map . Right . Height != 0 ) yield return map . Right ; if ( parentIndex == - 1 ) break ; yield return map = parentStack [ parentIndex -- ] ; map = map . Right ; } else { parentStack [ ++ parentIndex ] = map ; map = map . Left ; } } } }
Returns all map tree nodes enumerated from the lesser to the bigger keys
Returns all map tree nodes enumerated from the lesser to the bigger keys
parentStack
ImMap<V>[]