/// <summary> /// Returns a hash code for this instance. /// </summary> /// <returns>A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.</returns> public override int GetHashCode() { unchecked { return(((Leafs?.GetHashCode() ?? 0) * 397) ^ ((Name?.GetHashCode() ?? 0) * 23) ^ (Definition?.GetHashCode() ?? 0)); } }
// search if value added to dict and return amount of this value public int GetAmount(char currVal, string stringValue) { // if current char of word-to-insert compares to char into this leaf if (currVal != LeafVal) { throw new Exception(); //todo() } if (stringValue.Length == 0) // if this char is last in word-to-insert { return(Amount); } else { char nextVal = stringValue[0]; if (Leafs.ContainsKey(nextVal)) // if further path exist -> continue search deeper { return(Leafs[nextVal].GetAmount(nextVal, stringValue.Substring(1))); } else { return(0); // there is no such word in dict } } }
/// <summary> /// Specific rule implementation of the match. /// </summary> /// <param name="state">The state.</param> /// <returns><c>true</c> if input is matched, <c>false</c> otherwise.</returns> protected internal override bool MatchImpl(ParserState state) { if (!Leafs.Any()) { Leafs.Add(RuleFunc()); } return(FirstLeaf.MatchImpl(state)); }
public virtual bool RemoveLeaf(Q q) { if (Leafs.ContainsKey(q.Text)) { Leafs.Remove(q.Text); return(true); } else { return(false); } }
public virtual ILeaf <T, Q> AddLeaf(Q q) { if (Leafs.ContainsKey(q.Text)) { return(null); } else { ILeaf <T, Q> r = new LeafBase <T, Q>(q); Leafs.Add(q.Text, r); return(r); } }
public virtual ILeaf <T, Q> Values(string key) { if (Leafs.ContainsKey(key)) { return(Leafs[key]); } else { return(null); } }
public static bool CompareLeafs(Leafs aLeafs, Leafs bLeafs) { for (int i = 0; i < 4; i++) { if (aLeafs.nums[i] != bLeafs.nums[i]) { return(false); } } return(true); }
/// <summary> /// Specific rule implementation of the match. Which matches if all rules match. /// </summary> /// <param name="state">The state.</param> /// <returns><c>true</c> if input is matched, <c>false</c> otherwise.</returns> protected internal override bool MatchImpl(ParserState state) { var oldState = state.Clone(); if (Leafs.All(c => c.MatchImpl(state))) { return(true); } state.Assign(oldState); return(false); }
public void Check() { if (Leafs.CompareLeafs(questionleafs, answerLeafs)) { obstaclePanel.SetActive(true); Invoke("DisplayObstaclePanel", 3.0f); StartCoroutine(answerLeafs.ClearEffect()); foreach (ValueLeafs leafs in leafses) { leafs.GoBack(); } if (stageList.Count < 1) { currentLevel = stageData.Level + 1; PlayerPrefs.SetInt("Level" + currentLevel, 1); } } }
// insert new value public void InsertValue(char currVal, string stringValue) { // if current char of word-to-insert compares to char into this leaf if (currVal != LeafVal) { throw new Exception(); //todo() } if (stringValue.Length == 0) // if this char is last in word-to-insert { Amount++; } else { char nextVal = stringValue[0]; if (!Leafs.ContainsKey(nextVal)) // if there wasnt such tree-way before (creating new path) { Leafs.Add(nextVal, new DictLeaf(nextVal)); } Leafs[nextVal].InsertValue(nextVal, stringValue.Substring(1)); // pushing remaining part of word-to-insert further to path } }
/// <summary> /// Equalses the specified other. /// </summary> /// <param name="other">The other.</param> /// <returns><c>true</c> if equal, <c>false</c> otherwise.</returns> protected bool Equals(Rule other) { return(Leafs.SequenceEqual(other.Leafs) && string.Equals(Name, other.Name) && string.Equals(Definition, other.Definition)); }
/// <summary> /// Gets the child leafs. /// </summary> /// <returns>IEnumerable<Rule>.</returns> public ReadOnlyCollection <Rule> GetLeafs() => Leafs.AsReadOnly();
/// <summary> /// Initializes a new instance of the <see cref="SequenceRule" /> class. /// </summary> /// <param name="rules">The rules.</param> public SequenceRule(IEnumerable <Rule> rules) { Leafs.AddRange(rules.SelectMany(FlattenRules)); }
/// <summary> /// Initializes a new instance of the <see cref="SequenceRule" /> class. /// </summary> /// <param name="firstRule">The first rule.</param> /// <param name="secondRule">The second rule.</param> /// <param name="rules">The rules.</param> public SequenceRule(Rule firstRule, Rule secondRule, params Rule[] rules) { var allRules = Util.MergeArray(firstRule, secondRule, rules); Leafs.AddRange(allRules.SelectMany(FlattenRules)); }
public void AddLeaf(Leaf l) { Leafs.Add(l); }
public void ApplyToLeafs(Leafs leafs) { leafs.nums = (int[])leafValue.Clone(); leafs.DisplayNumbers(); }