private TDfaState BuildState()
                {
                    try
                    {
                        if (_builder._frozenNodesDictionary.TryGetValue(_nodesCollection, out _frozenNodes) == false)
                        {
                            _frozenNodes = _nodesCollection.Freeze();
                            _builder._frozenNodesDictionary[_frozenNodes] = _frozenNodes;
                        }

                        if (_builder._frozenLazyTransitionsDictionary.TryGetValue(_lazyTransitionsCollection, out _frozenTransitions) == false)
                        {
                            _frozenTransitions = _lazyTransitionsCollection.Freeze();
                            _builder._frozenLazyTransitionsDictionary[_frozenTransitions] = _frozenTransitions;
                        }

                        _stateHashCode = 0;

                        unchecked
                        {
                            _stateHashCode *= 397;
                            _stateHashCode ^= _frozenNodes.ElementsHashCode;

                            _stateHashCode *= 397;
                            _stateHashCode ^= _frozenTransitions.ElementsHashCode;

                            _stateHashCode *= 397;
                            _stateHashCode ^= _successTransition?.GetHashCode() ?? 0;

                            _stateHashCode *= 397;
                            _stateHashCode ^= _prevSuccessTransition?.GetHashCode() ?? 0;
                        }

                        if (_builder._frozenStatesDictionary.TryGetValue(this, out var frozen))
                        {
                            return(frozen);
                        }

                        frozen = _builder.CreateDfaState(_frozenNodes.Elements, _frozenTransitions.Elements, _successTransition, _prevSuccessTransition, _stateHashCode);

                        var stateKey   = new DfaFrozenStateKey(frozen);
                        var stateValue = _nodesCollection.Count == 0 ? null : frozen;

                        _builder._frozenStatesDictionary[stateKey] = stateValue;

                        return(stateValue);
                    }
                    finally
                    {
                        Clear();
                    }
                }
Ejemplo n.º 2
0
            public override int GetHashCode()
            {
#if NETCOREAPP
                return(HashCode.Combine(Node, Transition, ExecutionPathObject));
#else
                unchecked
                {
                    int hash = 17;

                    hash = hash * 31 + Node.GetHashCode();
                    hash = hash * 31 + Transition.GetHashCode();

                    if (ExecutionPathObject != null)
                    {
                        hash = hash * 31 + ExecutionPathObject.GetHashCode();
                    }

                    return(hash);
                }
#endif
            }