public void ChangeSortOption(SortOption sortOption)
        {
            switch (sortOption)
            {
            case SortOption.Bubble:
                _sortStrategy = new BubbleSort <T>();
                break;

            case SortOption.Insertion:
                _sortStrategy = new InsertionSort <T>();
                break;

            case SortOption.Selection:
                _sortStrategy = new SelectionSort <T>();
                break;

            case SortOption.Heap:
                _sortStrategy = new HeapSort <T>();
                break;

            case SortOption.Quick:
                _sortStrategy = new QuickSort <T>();
                break;

            default:
                _sortStrategy = new BubbleSort <T>();
                break;
            }
        }
        public void Sort(SortableList sortableList)
        {
            ISortStrategy sortingStrategy = efficientSortingStrategyFinder.GetEfficientStrategy(sortableList);

            sortableList.SortStrategy = sortingStrategy;
            sortableList.Sort();
        }
Esempio n. 3
0
 public void PhotosData(PictureBox i_PictureBox, GroupBox i_GroupBoxStatistics)
 {
     m_PictureBox         = i_PictureBox;
     m_GroupBoxStatistics = i_GroupBoxStatistics;
     SortStrategy         = new SortByDate();
     UpdatePicture();
 }
Esempio n. 4
0
        private void WriteResults(ISortStrategy sortStrategy)
        {
            var timer = Stopwatch.StartNew();

            Console.WriteLine($"Write results to file {_options.Output}...");

            sortStrategy.WriteResult(_options.Output);

            Console.WriteLine($"Results written at {timer.Elapsed}");
        }
 /// <summary>
 /// The constructor takes the input data and selects the proper sort strategy
 /// </summary>
 /// <param name="data">The list of data</param>
 public SortStrategySelector(IList <T> data)
 {
     _data = data;
     if (data.Count < 10)
     {
         SortStrategy = new BubbleSortStrategy <T>();
     }
     else
     {
         SortStrategy = new QuickSortStrategy <T>();
     }
 }
 public long Sort(int[] data, ISortStrategy strategy)
 {
     if (!isInited)
     {
         throw new Exception ("Application should be initialized first!");
     }
     System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch ();
     watch.Reset ();
     watch.Start ();
     strategy.Sort (ref data);
     watch.Stop ();
     return watch.ElapsedMilliseconds;
 }
Esempio n. 7
0
        private void comboBoxSort_SelectedIndexChanged(object sender, EventArgs e)
        {
            string selectedItem = comboBoxSort.SelectedItem.ToString();

            if (selectedItem == "Alphabetical")
            {
                m_SortStrategy = new NameStrategy();
            }
            else if (selectedItem == "Date")
            {
                m_SortStrategy = new DateStrategy();
            }
        }
Esempio n. 8
0
        public SortedQueue GetAllSortedTransaction(List <Models.TransactionQueue> pendingTransactions, string sortedColumnName, int sortedDirection, int page, int pageSize)
        {
            colsortStrategy   = new ColumnSorting(_priorityRules, _transactionQueueRepository);
            smartsortStrategy = new SmartSorting(_priorityRules, _transactionQueueRepository);

            if (!string.IsNullOrEmpty(sortedColumnName))
            {
                return(colsortStrategy.GetSortedQueue(pendingTransactions, sortedColumnName, sortedDirection, page, pageSize));
            }
            else
            {
                return(smartsortStrategy.GetSortedQueue(pendingTransactions, sortedColumnName, sortedDirection, page, pageSize));
            }
        }
Esempio n. 9
0
		private static (TimeSpan duration, List<int> sortedData) RunTest(ISortStrategy sortStrategy, List<int> unsortedData, int testsCount)
		{
			var duration = TimeSpan.Zero;
			List<int> sortedData = new List<int>();

			for (int i = 0; i < testsCount; i++)
			{
				var startTime = DateTime.Now;
				sortedData = sortStrategy.Sort(unsortedData);
				duration += DateTime.Now - startTime;

			}
			return (duration, sortedData);
		}
        public void SortStrategyFactory_CreateSort_MergeSortValue_CreateMergeSortInstance()
        {
            ISortTypeFactory sortTypeFactory = CreateSortTypeFactory();
            var          sortStrategyFactory = new SortStrategyFactory(sortTypeFactory);
            IStepCounter stepCounter         = new StubIStepCounter()
            {
                CountSwapOperation    = () => { },
                CountCompareOperation = () => { }
            };

            ISortStrategy sortStrategy = sortStrategyFactory.CreateSort(SortAlgorithmEnum.MergeSort, SortTypeEnum.Ascending, stepCounter);

            Assert.IsInstanceOfType(sortStrategy, typeof(MergeSort));
        }
Esempio n. 11
0
        public MyArray(int _quantity, ISortStrategy strategy)
        {
            array         = new int[_quantity];
            this.quantity = _quantity;
            SortStrategy  = strategy;
            Random rand = new Random();

            Console.WriteLine("Our array of elements:");
            for (int i = 0; i < _quantity; i++)
            {
                array[i] = rand.Next(1, 100);
                Console.Write(array[i] + " ");
            }
        }
Esempio n. 12
0
        private void OnStartClick(object sender, RoutedEventArgs e)
        {
            if (AlgorithmComboBox.SelectedItem == null)
            {
                return;
            }

            InitializeCollectionWithRandonNumbers(_collection, Size);

            _sorter = (ISortStrategy)AlgorithmComboBox.SelectedItem;
            _sorter.ReportProgress += UpdateProgress;

            StartSorting();
        }
        public IList <IWatchedFile> GetAvailableImages(IWatchedFileRepository watchedFileRepository, string path, IList <string> acceptableExtensions, bool includeSubDirectories,
                                                       ISortStrategy sortStrategy)
        {
            _log.DebugFormat("Beginning to list available images: {0}", path);

            var imageFiles = new List <IWatchedFile>();

            _acceptableExtensions  = acceptableExtensions;
            _includeSubDirectories = includeSubDirectories;

            PopulateFilesForFolder(watchedFileRepository, imageFiles, path);

            _log.DebugFormat("Returning list of available images: {0} with count {1}", path, imageFiles.Count);

            return(imageFiles);
        }
Esempio n. 14
0
    public static void AssertTestRowSort(
      string title,
      ISortStrategy<TestLine> strategy,
      int blockSize
    )
    {
      var input = GenerateTestRows(blockSize);
      var expected = input.OrderBy(x => x.String).ThenBy(x => x.Number).Select(x => _parser.Unparse(x)).ToArray();

      var watch = new Stopwatch();
      watch.Start();

      var actual = strategy.Sort(input).Select(x => _parser.Unparse(x)).ToArray();
      watch.Stop();

      Assert.Equal(expected, actual);
    }
Esempio n. 15
0
 public FileSorter(
     ILineParser <T> lineParser,
     ISortStrategy <GroupedItem <T> > sortStrategy,
     IComparer <GroupedItem <T> > comparer,
     IFileAdapter fileAdapter,
     IFileReader filereader,
     IFileWriter fileWriter,
     IProgress <SortProgress> progress = null
     )
 {
     _lineParser   = lineParser;
     _sortStrategy = sortStrategy;
     _comparer     = comparer;
     _fileAdapter  = fileAdapter;
     _fileReader   = filereader;
     _fileWriter   = fileWriter;
     _progress     = progress;
 }
        public void Configure(IWatchDirectory watchDir)
        {
            _watchPath = watchDir.Path;
            _includeSubDirectories = watchDir.IncludeSubDirectories;
            _mode = watchDir.Mode;

            var strategy = watchDir.SortStrategy;
            if (string.IsNullOrEmpty(strategy))
            {
                _sortStrategy = _entityLocator.ProvideDefaultSortStrategy();
            }
            else
            {
                strategy = strategy.ToLower();
                _sortStrategy = _entityLocator.ProvideSortStrategy(strategy);
            }

            foreach (string ext in watchDir.FileExtensions.Split(','))
            {
                _acceptableExtensions.Add(string.Format(".{0}", ext));
            }
        }
Esempio n. 17
0
        public void Configure(IWatchDirectory watchDir)
        {
            _watchPath             = watchDir.Path;
            _includeSubDirectories = watchDir.IncludeSubDirectories;
            _mode = watchDir.Mode;

            var strategy = watchDir.SortStrategy;

            if (string.IsNullOrEmpty(strategy))
            {
                _sortStrategy = _entityLocator.ProvideDefaultSortStrategy();
            }
            else
            {
                strategy      = strategy.ToLower();
                _sortStrategy = _entityLocator.ProvideSortStrategy(strategy);
            }

            foreach (string ext in watchDir.FileExtensions.Split(','))
            {
                _acceptableExtensions.Add(string.Format(".{0}", ext));
            }
        }
Esempio n. 18
0
        private void SplitData(ISortStrategy sortStrategy, DataRecordReader reader, long fileLength)
        {
            var timer = Stopwatch.StartNew();

            var readerPositionPrev = 0L;

            foreach (var dataRecord in reader)
            {
                var readerPosition = reader.Position;
                if (readerPosition - readerPositionPrev > Constants.HundredMegabytes)
                {
                    ShowProgress(readerPosition, fileLength, timer.Elapsed.TotalSeconds);
                    readerPositionPrev = readerPosition;
                }

                sortStrategy.Aggregate(dataRecord);
            }

            ShowProgress(reader.Position, fileLength, timer.Elapsed.TotalSeconds);

            Console.WriteLine();
            Console.WriteLine($"Splitting executed at {timer.Elapsed}");
        }
Esempio n. 19
0
        public CancellationTokenSource StartNew(string fileName, Action <SortFinishedArgs> postSortAction)
        {
            var source = new CancellationTokenSource();
            var token  = source.Token;

            var factory = new TaskFactory(token);

            factory.StartNew(() =>
            {
                ISortStrategy strategy = null;

                try
                {
                    token.Register(Thread.CurrentThread.Abort);
                    var memoryChecker   = new MemoryChecker();
                    var strategyFactory = new SortStrategyFactory(memoryChecker);
                    strategy            = strategyFactory.ChooseSortStrategy(fileName);
                    strategy.Sort();
                    postSortAction(new SortFinishedArgs());
                }
                catch (ThreadAbortException)
                {
                    // do nothing, operation was cancelled
                }
                catch (Exception exception)
                {
                    var args = new SortFinishedArgs(exception);
                    postSortAction(args);
                }
                finally
                {
                    strategy.CleanUp();
                }
            }, token);
            return(source);
        }
Esempio n. 20
0
 public SortProcessor(ISortStrategy strategy)
 {
     _strategy = strategy;
     _timer    = new Stopwatch();
 }
Esempio n. 21
0
 public IList <int> Sort(IList <int> unSortedList, ISortStrategy sortStrategy) => sortStrategy.Sort(unSortedList);
Esempio n. 22
0
 public void SetSortingStrategy(ISortStrategy sortStrategy)
 {
     _sortStrategy = sortStrategy;
 }
Esempio n. 23
0
 public DataContainer(ISortStrategy s)
 {
     this.sortStrategy = s;
 }
Esempio n. 24
0
 public Sorter(ISortStrategy sorter)
 {
     mSorter = sorter;
 }
Esempio n. 25
0
 public void SetSortedListContext(ISortStrategy sortStrategy)
 {
     this._sortStrategy = sortStrategy;
 }
 public void Setup()
 {
     _sut = new DoNotSortStrategy();
 }
 public CheckinsSorter(ISortStrategy i_Strategy)
 {
     SortStrategy = i_Strategy;
 }
Esempio n. 28
0
 internal SortContext(ISortStrategy sortStrategy)
 {
     _sortStrategy = sortStrategy;
 }
 public void Setup()
 {
     _sut = new LastNameSortStrategy();
 }
 public void Setup()
 {
     _sut = new FemalesFirstSortStrategy();
 }
Esempio n. 31
0
 private void DoSortTests(ISortStrategy<int> strategy)
 {
     Assert.IsTrue(RandomArray(10, 100).Sort<int>(strategy, SortOrder.Asc).IsSorted<int>(SortOrder.Asc));
     Assert.IsTrue(RandomArray(1000, 10000).Sort<int>(strategy, SortOrder.Desc).IsSorted<int>(SortOrder.Desc));
 }
 public void Sort(ISortStrategy sortStrategy)    //sortStrategy can be passed in constructor or like method parameter.
 {
     sortStrategy.Sort(list);
 }
Esempio n. 33
0
 public void SetUpBeforeEveryTest() {
     Nodes.Init();
     sortStrategy = new RandomSortStrategy(Vector2.zero, d, w, h);
 }
Esempio n. 34
0
 public void setSortStrategy(ISortStrategy s)
 {
     this.sortStrategy = s;
 }
Esempio n. 35
0
 private void btnS1_Click(object sender, EventArgs e)
 {
     _sortStrategy = new SimpleSortStrategy();
     SortReports();
 }
Esempio n. 36
0
 public Strategy(ISortStrategy sortStrategy)
 {
     _sortStrategy = sortStrategy;
 }
Esempio n. 37
0
 private void btnS2_Click(object sender, EventArgs e)
 {
     _sortStrategy = new InformationQuantityStrategy();
     SortReports();
 }
 public void Setup()
 {
     _sut = new BirthDateSortStrategy();
 }
Esempio n. 39
0
 public SortNamesExecution(IPersonDataSource dataSource, ISortStrategy sortStrategy, IEnumerable<IPeopleDisplayer> displayers)
 {
     _dataSource = dataSource;
     _sortStrategy = sortStrategy;
     _displayers = displayers;
 }
 public Sorter(ISortStrategy sorter)
 {
     this.sorter = sorter;
 }
 public void SetSortStrategy(ISortStrategy strategy)
 {
     _sortStrategy = strategy;
 }