static void Main(string[] args) { BinarySearchTree <int, String> tree = new BinarySearchTree <int, string>(); int[] arr = new int[] { 1, 7, 3, 6, 1, 9, 0, 7, 5, 4 }; var result = SortFunctions <int> .Sort(arr, SortingTechniques.MERGE_SORT); }
private void btn_run_Click(object sender, EventArgs e) { //Check to see if all of the values set are ok Boolean OK = true; //Passenger File if (txt_pdf.Text.Equals("")) { MessageBox.Show("Passenger File Required"); OK = false; } else { //Check it exists if (!File.Exists(txt_pdf.Text)) { MessageBox.Show("Passenger File Does not Exist"); OK = false; } } //Airport File if (txt_apt.Text.Equals("")) { MessageBox.Show("Airport File Required"); OK = false; } else { //Check it exists if (!File.Exists(txt_pdf.Text)) { MessageBox.Show("Airport File Does not Exist"); OK = false; } } //Output Directory if (txt_output.Text.Equals("")) { MessageBox.Show("Ouput Directiry Required"); OK = false; } else { // check the directory existis if (!Directory.Exists(txt_output.Text)) { MessageBox.Show("Output Directory Does not Exist"); } } //Check to see if it's all ok and then run if (OK) { //Clear the log txt_log.Text = ""; txt_log.Text = "Starting New MapReduce"; //create a new Mapper Object Mapper mapper = new Mapper(); //Set the files to be used mapper.AirportFile = txt_apt.Text; mapper.PassengerFile = txt_pdf.Text; mapper.outputPath = txt_output.Text; mapper.log = txt_log; //Map the Airports synchronously as we need to validate the airports for the passenger files //Start with Mapping the Airports file. mapper.MapAirports(); //Map the passenger File mapper.MapPassengers(); //Now start Sorting SortFunctions SF = new SortFunctions(); SF.outputpath = mapper.outputPath; //Now add a dictionary of the mappers so that it can run on multiple threads. Dictionary <string, string[]> MapOutput = new Dictionary <string, string[]>(); //Add the inputfiles required //A list of all flights from airport and the list of airport codes string[] FlightAirportFiles = { mapper.AptLatFile, mapper.FromAirportFile }; MapOutput.Add("FlightsAirport", FlightAirportFiles); //Passengers for each flight Sorter string[] PassengerFlightFiles = { mapper.FlightPassengerFile }; MapOutput.Add("FlightPassengers", PassengerFlightFiles); //Distance For each Flight string[] DistanceFlightFiles = { mapper.AptLatFile, mapper.AptLonFile, mapper.FlightDepArptFile, mapper.FlightDestFile, mapper.FlightPassengerFile }; MapOutput.Add("FlightDistance", DistanceFlightFiles); //All flight Information string[] AllFlightInfo = { mapper.FlightPassengerFile, mapper.FlightDepArptFile, mapper.FlightDestFile, mapper.FlightDepTimeFile, mapper.FlightTimeFile }; MapOutput.Add("AllFlightInfo", AllFlightInfo); //Now do the garbage collection from the mappers mapper = null; GC.Collect(); //Now set the multithreading options //We will just have one Sorter per thread and set the maximum number of thread to processor /2 to avoid memory issues //Each sorter will then go to the relevant reducers var Paralleloptions = new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount / 2 }; Parallel.ForEach(MapOutput, Paralleloptions, MapperOut => { //Now run the required Sorter SF.Sort(MapperOut.Key, MapperOut.Value); //Garbage collect each thread to free up any memory still left GC.Collect(); GC.WaitForPendingFinalizers(); }); //Update the Log window txt_log.AppendText(SF.LogWindow); //All done, now show the output folder in explorer } else { } }