public SerializableDfa(RawDfa <TResult> rawDfa) { var origStates = rawDfa.States; var len = origStates.Count; dfaStates = new List <DfaStatePlaceholder <TResult> >(len); startStateNumbers = rawDfa.StartStates; while (dfaStates.Count < len) { dfaStates.Add(new PackedTreeDfaPlaceholder <TResult>(rawDfa, dfaStates.Count)); } }
public DfaMinimizer(RawDfa <TResult> dfa) { origDfa = dfa; origStates = dfa.States; origBackReferences = _createBackReferences(); origOrderPartNums = new int[origStates.Count]; partitionOrderStates = new int[origStates.Count]; origOrderHashes = new int[origStates.Count]; scratchSpace = new int[origStates.Count]; scratchPartitions = new int[origStates.Count]; hashTableSize = PrimeSizeFinder.FindPrimeSize(origStates.Count); hashBuckets = new int[hashTableSize]; newStartStates = new int[origDfa.StartStates.Length]; CreateMinimalPartitions(); CreateNewStates(); }
internal PackedTreeDfaPlaceholder(RawDfa <TResult> rawDfa, int stateNum) { var info = rawDfa.States[stateNum]; (accepting, match) = rawDfa.AcceptSets[info.GetAcceptSetIndex()]; var rawTransCount = info.GetTransitionCount(); if (rawTransCount <= 0) { internalNodes = Constants.NoChars; targetStateNumbers = new[] { -1 }; return; } //Find all characters c such that the transition for c //is different from the transition for c-1 var tempChars = new char[rawTransCount * 2]; var len = 0; var trans = info.GetTransition(0); if (trans.FirstChar != '\0') { tempChars[len++] = trans.FirstChar; } for (var i = 1; i < rawTransCount; ++i) { var nextTrans = info.GetTransition(i); if (nextTrans.FirstChar > trans.LastChar + 1) { //there's a gap between transitions tempChars[len++] = (char)(trans.LastChar + 1); tempChars[len++] = nextTrans.FirstChar; } else if (nextTrans.State != trans.State) { tempChars[len++] = nextTrans.FirstChar; } trans = nextTrans; } if (trans.LastChar != char.MaxValue) { tempChars[len++] = (char)(trans.LastChar + 1); } if (len < 1) { //all characters same transition internalNodes = Constants.NoChars; targetStateNumbers = new[] { trans.State }; return; } //make the packed tree internalNodes = new char[len]; targetStateNumbers = new int[len + 1]; _transcribeSubtree(0, new TranscriptionSource(tempChars, info)); }