internal class Program
{
private static void Main(string[] args)
{
// Create a unique value
var unique = new MyStruct("Unique".GetHashCode(), 0x200);
// Prepare for all test cases
var executionArray = new Func[]
{
executeFindCustomStructWithLinq,
executeFindUniqueWithHashSet,
executeFindUniqueWithBinaryTree
};
// Execute test cases and get results
var resultsTypeArray = executionArray.Select( method => new {Name = nameof(method), Result = method(unique)});
// print the results from the case
resultsTypeArray.ToList().ForEach(item => WriteResults(item.Name,unique,item.Result));
Console.ReadKey();
}
private static void WriteResults(string methodName, MyStruct orig, MyStruct target)
{
Console.WriteLine($"{methodName}: {orig} == {target}");
}
private static IList CreateDataSet(MyStruct unique)
{
var random = new Random();
var amount = random.Next(0X0, 0x100);
var myStructFactory = MyStructFactory.Instance;
var dataSet = new List((amount*2) + 1);
dataSet.AddRange(myStructFactory.Create(amount));
// create a copy of the base data set
var holdingBuffer = new MyStruct[dataSet.Count];
dataSet.CopyTo(holdingBuffer, 0);
// Insert Unique somewhere in the set
dataSet.Insert(random.Next(0, dataSet.Count), unique);
// add duplicated base dataset
dataSet.AddRange(holdingBuffer);
return dataSet;
}
#region ExecutionExamples
private static MyStruct executeFindUniqueWithBinaryTree(MyStruct unique)
{
// Keep in mind this would only work if we knew the value before trying to parse the data set.
var dataSet = CreateDataSet(unique);
var orderedDataSet = dataSet.OrderBy(@struct => @struct).ToArray();
var start = 0;
var identifiedUnique = new MyStruct();
var end = orderedDataSet.Count();
while (start ();
var identifiedUnique = new MyStruct();
for (var i = 0; i a ^= b);
return identifiedUnique;
}
#endregion
}