module AlgorithmSelector
algorithm-selector library; 5 methods (all, best, analyze, compare, sort)
Constants
- VERSION
Public Instance Methods
all(action, data_set, trials=1, target=nil)
click to toggle source
Returns the times for each algorithm
# 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)
click to toggle source
Returns time for specified algorithm or data structure
# 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)
click to toggle source
Returns the algorithm with the best time
# 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)
click to toggle source
Returns the times of two specified algorithms for comparison
# 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)
click to toggle source
Returns sorted data_set of specified sorting algorithm
# File lib/algorithm_selector.rb, line 44 def sort(data_set, algorithm) method = Sorts.new.method(algorithm) method.call(data_set) end