Module: AlgorithmSelector
- Extended by:
- AlgorithmSelector
- Included in:
- AlgorithmSelector
- Defined in:
- lib/algorithm_selector.rb,
lib/algorithm_selector/version.rb
Overview
algorithm-selector library; 5 methods (all, best, analyze, compare, sort)
Constant Summary
- VERSION =
"0.1.5"
Instance Method Summary collapse
-
#all(action, data_set, trials = 1, target = nil) ⇒ Object
Returns the times for each algorithm.
-
#analyze(action, data_set, algorithm, trials = 1, target = nil) ⇒ Object
Returns time for specified algorithm or data structure.
-
#best(action, data_set, trials = 1, target = nil) ⇒ Object
Returns the algorithm with the best time.
-
#compare(action, data_set, first_algorithm, second_algorithm, trials = 1, target = nil) ⇒ Object
Returns the times of two specified algorithms for comparison.
-
#sort(data_set, algorithm) ⇒ Object
Returns sorted data_set of specified sorting algorithm.
Instance Method Details
#all(action, data_set, trials = 1, target = nil) ⇒ Object
Returns the times for each algorithm
8 9 10 11 12 13 14 |
# File 'lib/algorithm_selector.rb', line 8 def all(action, data_set, trials=1, target=nil) if action == "sort" Sorts.new.all(data_set, trials) elsif action == "search" Searches.new.all(data_set, trials, target) end end |
#analyze(action, data_set, algorithm, trials = 1, target = nil) ⇒ Object
Returns time for specified algorithm or data structure
26 27 28 29 30 31 32 |
# File 'lib/algorithm_selector.rb', line 26 def analyze(action, data_set, algorithm, trials=1, target=nil) if action == "sort" Sorts.new.analyze(data_set, algorithm, trials) elsif action == "search" Searches.new.analyze(data_set, algorithm, trials, target) end end |
#best(action, data_set, trials = 1, target = nil) ⇒ Object
Returns the algorithm with the best time
17 18 19 20 21 22 23 |
# File 'lib/algorithm_selector.rb', line 17 def best(action, data_set, trials=1, target=nil) if action == "sort" Sorts.new.best(data_set, trials) elsif action == "search" Searches.new.best(data_set, trials, target) end end |
#compare(action, data_set, first_algorithm, second_algorithm, trials = 1, target = nil) ⇒ Object
Returns the times of two specified algorithms for comparison
35 36 37 38 39 40 41 |
# File 'lib/algorithm_selector.rb', line 35 def compare(action, data_set, first_algorithm, second_algorithm, trials=1, target=nil) if action == "sort" Sorts.new.compare(data_set, first_algorithm, second_algorithm, trials) elsif action == "search" Searches.new.compare(data_set, first_algorithm, second_algorithm, trials, target) end end |
#sort(data_set, algorithm) ⇒ Object
Returns sorted data_set of specified sorting algorithm
44 45 46 47 |
# File 'lib/algorithm_selector.rb', line 44 def sort(data_set, algorithm) method = Sorts.new.method(algorithm) method.call(data_set) end |