/// <summary> /// Gets the hash code /// </summary> /// <returns>Hash code</returns> public override int GetHashCode() { // credit: http://stackoverflow.com/a/263416/677735 unchecked // Overflow is fine, just wrap { int hash = 41; // Suitable nullity checks hash = hash * 59 + Id.GetHashCode(); if (OldTable != null) { hash = hash * 59 + OldTable.GetHashCode(); } if (NewTable != null) { hash = hash * 59 + NewTable.GetHashCode(); } if (OldKey != null) { hash = hash * 59 + OldKey.GetHashCode(); } hash = hash * 59 + NewKey.GetHashCode(); return(hash); } }
/// <summary> /// Returns true if ImportMap instances are equal /// </summary> /// <param name="other">Instance of ImportMap to be compared</param> /// <returns>Boolean</returns> public bool Equals(ImportMap other) { if (other is null) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return (( Id == other.Id || Id.Equals(other.Id) ) && ( OldTable == other.OldTable || OldTable != null && OldTable.Equals(other.OldTable) ) && ( NewTable == other.NewTable || NewTable != null && NewTable.Equals(other.NewTable) ) && ( OldKey == other.OldKey || OldKey != null && OldKey.Equals(other.OldKey) ) && ( NewKey == other.NewKey || NewKey.Equals(other.NewKey) )); }
private static int RecursiveSetSudokuValue(ref Dictionary <int, int> dOldValue, ref Dictionary <string, string> dict, int pos, ref int RecCheck, int Value) { bool CheckCol = true; bool CheckRow = true; bool CheckSq = true; bool ValueAdded = false; int OldKey; int OldValue; int iRes = 0; // Create List object that will hold zero list List <int> dZList = new List <int>(); RecCheck++; Debug.WriteLine("Inside RecursiveSetSudokuValue for the: " + RecCheck + " time"); for (int i = Value; i <= 9; i++) { //Check unique value for Column CheckCol = GetColumn(dict, pos, i.ToString()); //Check unique value for Row CheckRow = GetRow(dict, pos, i.ToString()); //Check unique value for Square CheckSq = GetSquare(dict, pos, i.ToString()); if ((CheckCol && CheckRow && CheckSq) == true) { Debug.WriteLine("Found a value to set; position: " + pos + " Value: " + i.ToString()); //Put values in the dictionary object that holds old values dOldValue.Add(pos, i); //Add new value to the given position on the Sudoku dict [pos.ToString()] = i.ToString(); ValueAdded = true; //Take the next square from the zero array only if not backtracked iRes = BuildZeroList(ref dZList, dict); //Search for end condition if (dZList.Count != 0) { Debug.WriteLine("Still there exists zeros: " + dZList.Count); Debug.WriteLine(" "); //call recursive function, set value to 1 since it's time to start from the beginning on the new position return(RecursiveSetSudokuValue(ref dOldValue, ref dict, dZList.First(), ref RecCheck, 1)); } else { Debug.WriteLine("Found a solution!"); return(1); } } } // In this case we have a problem; we couldn't find a number to add //So we have to backtrack using our list of previous added numbers while (true) { if (ValueAdded == false) { //OldKey = dOldValue.ElementAt(0).Key; OldKey = dOldValue.Last().Key; //Set back to zero OldValue = dOldValue.Last().Value; //Check that oldvalue is not greater than nine if ((OldValue + 1) != 10) { //Add a zero to the old key in the Sudoku dict[OldKey.ToString()] = 0.ToString(); //Remove the key, value numbers from the list of previous added numbers dOldValue.Remove(dOldValue.Last().Key); //Check if there still exists old values to backtrack if (dOldValue.Count != 0) { //Recursive call to SetSudokuValue Debug.WriteLine("Didn't find any values to set in position " + pos); Debug.WriteLine("Calling RecursiveSetSudokuValue with position: " + OldKey + " and value: " + OldValue); Debug.WriteLine(" "); return(RecursiveSetSudokuValue(ref dOldValue, ref dict, OldKey, ref RecCheck, OldValue + 1)); } return(0); } //We have reach a nine, we need to backtrack once more else { //Add a zero to the Zudoku dict[OldKey.ToString()] = 0.ToString(); //Remove the key, value numbers from the list of previous added numbers dOldValue.Remove(dOldValue.Last().Key); } } } }