private void AssignAction(int state, int token, ParserAction action) { int cell = ParserAction.Encode(action); int currentCell = actionTable.Get(state, token); if (currentCell == 0) { actionTable.Set(state, token, cell); } else if (currentCell != cell) { int resolvedCell; if (!TryResolveShiftReduce(currentCell, cell, token, out resolvedCell)) { RequiresGlr = true; ParserConflictInfo conflict; var key = new TransitionKey(state, token); if (!transitionToConflict.TryGetValue(key, out conflict)) { conflict = new ParserConflictInfo(state, token); transitionToConflict[key] = conflict; conflict.AddAction(currentCell); } if (!conflict.Actions.Contains(action)) { conflict.AddAction(action); } } actionTable.Set(state, token, resolvedCell); } }
// private methods private TransitionKey GetKey(TEnum from, TEnum to) { int ifrom = EnumInt32ToInt.Convert(from); int ito = EnumInt32ToInt.Convert(to); var key = new TransitionKey(ifrom, ito); return(key); }
public StateNode NextState(TransitionKey tk, bool fAdd) { StateNode state = null; if (_mpchstate.ContainsKey(tk)) { state = _mpchstate[tk]; } else if (fAdd) { state = new StateNode(); _mpchstate.Add(tk, state); } return(state); }
private TrieNode GetOrCreateNextState(TrieNode node, char c) { TransitionTarget transitionTarget; var transition = new TransitionKey(node.NodeId, c); if (!transitions.TryGetValue(transition, out transitionTarget)) { var newNode = AddNode(node, c); // Creating new outgoing edge and store character corresponding to // existing outgoing edge (this way outgoing edges for single vertex form a linked list) transitionTarget = new TransitionTarget(newNode.NodeId, node.FirstOutgointChar); // Updating reference to top of linked list of node.UpdateOutgoingChar(c); transitions.Add(transition, transitionTarget); return(newNode); } return(nodes[transitionTarget.NextNodeId]); }
private TrieNode GetNextState(TrieNode node, char c) { TransitionTarget transitionTarget; var transition = new TransitionKey(node.NodeId, c); if (transitions.TryGetValue(transition, out transitionTarget)) { return(nodes[transitionTarget.NextNodeId]); } foreach (var n in TraversePrefixes(node)) { transition = new TransitionKey(n.NodeId, c); if (transitions.TryGetValue(transition, out transitionTarget)) { return(nodes[transitionTarget.NextNodeId]); } } return(null); }
public float? CalcTransitionRatio(TransitionGroupDocNode nodeGroup, TransitionDocNode nodeTran, IsotopeLabelType labelTypeNum, IsotopeLabelType labelTypeDenom) { // Avoid 1.0 ratios for self-to-self if (ReferenceEquals(labelTypeNum, labelTypeDenom)) return null; float areaNum, areaDenom; var key = nodeTran.Key(nodeGroup); var keyNum = new TransitionKey(nodeGroup, key, labelTypeNum); var keyDenom = new TransitionKey(nodeGroup, key, labelTypeDenom); if (!TranAreas.TryGetValue(keyNum, out areaNum) || !TranAreas.TryGetValue(keyDenom, out areaDenom)) return null; return areaNum/areaDenom; }
public float? CalcTransitionGlobalRatio(TransitionGroupDocNode nodeGroup, TransitionDocNode nodeTran, IsotopeLabelType labelType) { if (GlobalStandardArea == 0) return null; float areaNum; var keyNum = new TransitionKey(nodeGroup, nodeTran.Key(nodeGroup), labelType); if (!TranAreas.TryGetValue(keyNum, out areaNum)) return null; return (float) (areaNum / GlobalStandardArea); }
public void AddChromInfo(TransitionGroupDocNode nodeGroup, TransitionDocNode nodeTran, TransitionChromInfo info) { if (info.IsEmpty) return; var key = new TransitionKey(nodeGroup, nodeTran.Key(nodeGroup), nodeGroup.TransitionGroup.LabelType); if (TranAreas.ContainsKey(key)) throw new InvalidDataException(String.Format(Resources.PeptideChromInfoCalculator_AddChromInfo_Duplicate_transition___0___found_for_peak_areas, nodeTran.Transition)); TranAreas.Add(key, info.Area); }
private bool Equals(TransitionKey other) { return Equals(other._ionType, _ionType) && Equals(_customIonEquivalenceTestValue, other._customIonEquivalenceTestValue) && other._ionOrdinal == _ionOrdinal && other._massIndex == _massIndex && Equals(other._decoyMassShift, _decoyMassShift) && other._charge == _charge && other._precursorCharge == _precursorCharge && Equals(other._losses, _losses) && Equals(other._labelType, _labelType); }
public TransitionKey(TransitionKey key, IsotopeLabelType labelType) { _ionType = key._ionType; _customIonEquivalenceTestValue = key._customIonEquivalenceTestValue; _ionOrdinal = key._ionOrdinal; _massIndex = key._massIndex; _decoyMassShift = key._decoyMassShift; _charge = key._charge; _precursorCharge = key._precursorCharge; _losses = key._losses; _labelType = labelType; }
//// Given a transition key, find the next state. Optionally, //// add a new state when the key isn't yet a valid transition //// for this state. //public StateNode NextState(TransitionKey tk, bool fAdd) //{ // StateNode state; // try // { // state = _mpchstate[tk]; // } // catch (KeyNotFoundException) // { // state = null; // } // if (state == null && fAdd) // { // state = new StateNode(); // _mpchstate.Add(tk, state); // } // return state; //} // Remove a given transition to another state from this state public void RemoveLink(TransitionKey tk) { _mpchstate.Remove(tk); }