def main(): event_bus = events.EventBus() event_bus.register(ListSortedEventListener()) sort_event_emitter = events.DefaultEventEmitter(event_bus) mock_thread_pool = threadpool.MockThreadPool() thread_pool = threadpool.RoundRobinThreadPool(8) thread_pool.start_threads() lst = make_list(LIST_LENGTH) strategies = [ # ('Selection sort', SelectionSort()), # ('Insertion sort', InsertionSort()), # ('Bubble sort', BubbleSort()), ('Merge sort (single-threaded)', MergeSort(mock_thread_pool)), ('Merge sort (multi-threaded)', MergeSort(thread_pool)), # ('Quick sort (first element)', QuickSort(PartitionOnFirstElement(), thread_pool)), # ('Quick sort (mid value)', QuickSort(PartitionOnMidVal(), thread_pool)), # ('Heap sort', HeapSort()) ] loop = asyncio.get_event_loop() try: result = loop.run_until_complete( run_algorithms(lst, strategies, sort_event_emitter)) finally: thread_pool.close_pool() loop.close()
def debug(): lst = [] for i in range(15): lst.append(random.randint(0, 20)) event_bus = events.EventBus() sorter = sorting.BubbleSort(sorting.ListState(lst, event_bus)) sorter.sort() print(lst)
def post_construct(self): self._event_bus = events.EventBus() if LOG_EVENTS: LoggingEventListener().register_bus(self._event_bus) self._event_listener = view.eventlistener.ApplicationEventListener( self) self._event_listener.register_bus(self._event_bus) self._board_store = store.board.BoardStore(self._event_bus) self._solver_store = store.solver.SolverStore(self._event_bus) self._event_listener.start(self._EVENT_LOOP_TIMEOUT) self._validator = validator.SolutionValidatorBuilder.solution_validator( self._board_store) self._render_widgets() # self._board_store.reset_board(7, 7) store.puzzles.PuzzleLoader.load_puzzle( self._board_store, store.puzzles.PuzzleLoader.HARD_25x25)
def main(): event_bus = events.EventBus() event_bus.register(ListSortedEventListener()) sort_event_emitter = events.DefaultEventEmitter(event_bus) lst = make_list(LIST_LENGTH) strategies = [ # ('Selection sort', SelectionSort()), # ('Insertion sort', InsertionSort()), # ('Bubble sort', BubbleSort()), ('Merge sort (single-threaded)', MergeSort()), ('Merge sort (multi-threaded)', MergeSort()), # ('Quick sort (first element)', QuickSort(PartitionOnFirstElement(), thread_pool)), # ('Quick sort (mid value)', QuickSort(PartitionOnMidVal(), thread_pool)), # ('Heap sort', HeapSort()) ] result = loop.run_until_complete( run_algorithms(lst, strategies, sort_event_emitter))
def _register_listeners(self): self._event_bus = events.EventBus() self._event_bus.register(self.controls) self._event_bus.register(self.counts) self._event_bus.register(self.canvas) self._event_bus.register(self)