Пример #1
0
        private void PreProcess()
        {
            // Eulerian path visit of graph
            Stack <ProcessingState> lastNodeStack = new Stack <ProcessingState>();
            ProcessingState         current       = new ProcessingState(_rootNode);
            ITreeNode <T>           next;

            lastNodeStack.Push(current);

            NodeIndex nodeIndex;
            int       valueIndex;

            while (lastNodeStack.Count != 0)
            {
                current = lastNodeStack.Pop();
                if (!_indexLookup.TryGetValue(current.Value, out nodeIndex))
                {
                    valueIndex = _nodes.Count;
                    _nodes.Add(current.Value);
                    _indexLookup[current.Value] = new NodeIndex(_values.Count, valueIndex);
                }
                else
                {
                    valueIndex = nodeIndex.LookupIndex;
                }
                _values.Add(valueIndex);

                // If there is a next then push the current value on to the stack along with
                // the current value.
                if (current.Next(out next))
                {
                    lastNodeStack.Push(current);
                    lastNodeStack.Push(new ProcessingState(next));
                }
            }
            _nodes.TrimExcess();
            _values.TrimExcess();
        }