Example #1
0
            /// <summary>
            /// Initializes an <see cref="Enumerator"/> structure.
            /// </summary>
            /// <param name="root">The root of the set to be enumerated.</param>
            /// <param name="builder">The builder, if applicable.</param>
            /// <param name="startIndex">The index of the first element to enumerate.</param>
            /// <param name="count">The number of elements in this collection.</param>
            /// <param name="reversed"><c>true</c> if the list should be enumerated in reverse order.</param>
            internal Enumerator(Node root, Builder builder = null, int startIndex = -1, int count = -1, bool reversed = false)
            {
                Requires.NotNull(root, nameof(root));
                Requires.Range(startIndex >= -1, nameof(startIndex));
                Requires.Range(count >= -1, nameof(count));
                Requires.Argument(reversed || count == -1 || (startIndex == -1 ? 0 : startIndex) + count <= root.Count);
                Requires.Argument(!reversed || count == -1 || (startIndex == -1 ? root.Count - 1 : startIndex) - count + 1 >= 0);

                _root                      = root;
                _builder                   = builder;
                _current                   = null;
                _startIndex                = startIndex >= 0 ? startIndex : (reversed ? root.Count - 1 : 0);
                _count                     = count == -1 ? root.Count : count;
                _remainingCount            = _count;
                _reversed                  = reversed;
                _enumeratingBuilderVersion = builder != null ? builder.Version : -1;
                _poolUserId                = SecureObjectPool.NewId();
                _stack                     = null;
                if (_count > 0)
                {
                    if (!s_EnumeratingStacks.TryTake(this, out _stack))
                    {
                        _stack = s_EnumeratingStacks.PrepNew(this, new Stack <RefAsValueType <Node> >(root.Height));
                    }

                    this.ResetStack();
                }
            }
Example #2
0
            /// <summary>
            /// Disposes of this enumerator and returns the stack reference to the resource pool.
            /// </summary>
            public void Dispose()
            {
                _root    = null !;
                _current = null;
                if (_stack != null && _stack.TryUse(ref this, out Stack <RefAsValueType <Node> >?stack))
                {
                    stack.ClearFastWhenEmpty();
                    SecureObjectPool <Stack <RefAsValueType <Node> >, Enumerator> .TryAdd(this, _stack !);
                }

                _stack = null;
            }
Example #3
0
            /// <summary>
            /// Initializes an <see cref="Enumerator"/> structure.
            /// </summary>
            /// <param name="root">The root of the set to be enumerated.</param>
            internal Enumerator(SortedInt32KeyNode <TValue> root)
            {
                Requires.NotNull(root, nameof(root));

                _root       = root;
                _current    = null;
                _poolUserId = SecureObjectPool.NewId();
                _stack      = null;
                if (!_root.IsEmpty)
                {
                    if (!s_enumeratingStacks.TryTake(this, out _stack))
                    {
                        _stack = s_enumeratingStacks.PrepNew(this, new Stack <RefAsValueType <SortedInt32KeyNode <TValue> > >(root.Height));
                    }

                    this.PushLeft(_root);
                }
            }
            /// <summary>
            /// Initializes an <see cref="Enumerator"/> structure.
            /// </summary>
            /// <param name="root">The root of the set to be enumerated.</param>
            /// <param name="builder">The builder, if applicable.</param>
            /// <param name="reverse"><c>true</c> to enumerate the collection in reverse.</param>
            internal Enumerator(Node root, Builder builder = null, bool reverse = false)
            {
                Requires.NotNull(root, nameof(root));

                _root    = root;
                _builder = builder;
                _current = null;
                _reverse = reverse;
                _enumeratingBuilderVersion = builder != null ? builder.Version : -1;
                _poolUserId = SecureObjectPool.NewId();
                _stack      = null;
                if (!s_enumeratingStacks.TryTake(this, out _stack))
                {
                    _stack = s_enumeratingStacks.PrepNew(this, new Stack <RefAsValueType <Node> >(root.Height));
                }

                this.PushNext(_root);
            }
Example #5
0
            /// <summary>
            /// Initializes an Enumerator structure.
            /// </summary>
            /// <param name="root">The root of the set to be enumerated.</param>
            internal Enumerator(SortedInt32KeyNode <TValue> root)
            {
                Requires.NotNull(root, "root");

                this.root       = root;
                this.current    = null;
                this.poolUserId = SecureObjectPool.NewId();
                this.stack      = null;
                if (!this.root.IsEmpty)
                {
                    if (!enumeratingStacks.TryTake(this, out this.stack))
                    {
                        this.stack = enumeratingStacks.PrepNew(this, new Stack <RefAsValueType <SortedInt32KeyNode <TValue> > >(root.Height));
                    }

                    this.PushLeft(this.root);
                }
            }
Example #6
0
            /// <summary>
            /// Initializes an <see cref="Enumerator"/> structure.
            /// </summary>
            /// <param name="root">The root of the set to be enumerated.</param>
            /// <param name="builder">The builder, if applicable.</param>
            internal Enumerator(Node root, Builder?builder = null)
            {
                Requires.NotNull(root, nameof(root));

                _root    = root;
                _builder = builder;
                _current = null;
                _enumeratingBuilderVersion = builder != null ? builder.Version : -1;
                _poolUserId = SecureObjectPool.NewId();
                _stack      = null;
                if (!_root.IsEmpty)
                {
                    if (!SecureObjectPool <Stack <RefAsValueType <Node> >, Enumerator> .TryTake(this, out _stack))
                    {
                        _stack = SecureObjectPool <Stack <RefAsValueType <Node> >, Enumerator> .PrepNew(this, new Stack <RefAsValueType <Node> >(root.Height));
                    }

                    this.PushLeft(_root);
                }
            }