master > master: src go - algorithmen + display methoden hinzugefügt
This commit is contained in:
@@ -5,16 +5,148 @@ package endpoints
|
||||
* ---------------------------------------------------------------- */
|
||||
|
||||
import (
|
||||
"ads/internal/core/logging"
|
||||
"ads/internal/setup"
|
||||
"ads/internal/types"
|
||||
"fmt"
|
||||
|
||||
algorithm_search_binary "ads/internal/algorithms/search/binary"
|
||||
algorithm_search_interpol "ads/internal/algorithms/search/interpol"
|
||||
algorithm_search_ith_element "ads/internal/algorithms/search/ith_element"
|
||||
algorithm_search_jump "ads/internal/algorithms/search/jump"
|
||||
algorithm_search_poison "ads/internal/algorithms/search/poison"
|
||||
algorithm_search_sequential "ads/internal/algorithms/search/sequential"
|
||||
algorithm_sum_maxsubsum "ads/internal/algorithms/sum/maxsubsum"
|
||||
"ads/internal/core/logging"
|
||||
)
|
||||
|
||||
/* ---------------------------------------------------------------- *
|
||||
* ENDPOINT run
|
||||
* ---------------------------------------------------------------- */
|
||||
|
||||
func Run(fnameConfig string) error {
|
||||
// Liest Config Datei ein und führt Algorithmen auf Fälle durch
|
||||
func Run(path string) error {
|
||||
var err error
|
||||
var err_case error
|
||||
|
||||
logging.LogPlain(setup.Logo())
|
||||
logging.LogWarn("Die Go-Implementierung ist noch unter Arbeit.")
|
||||
|
||||
// extrahiere user config
|
||||
config := setup.NewUserConfig()
|
||||
err = setup.GetUserConfig(path, &config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Fälle extrahieren
|
||||
cases := []types.CaseConfig{}
|
||||
if config.Parts != nil && config.Parts.Cases != nil {
|
||||
cases = *config.Parts.Cases
|
||||
}
|
||||
for i := 0; i < len(cases); i++ {
|
||||
err_case = nil
|
||||
problem := cases[i]
|
||||
setup.DisplayStartOfCase(i, problem.Description)
|
||||
inputs := types.InputsConfig{}
|
||||
if problem.Inputs != nil {
|
||||
inputs = *problem.Inputs
|
||||
}
|
||||
if problem.Command == nil {
|
||||
err_case = fmt.Errorf("Attribute 'command:' fehlt!")
|
||||
} else {
|
||||
switch *problem.Command {
|
||||
case "algorithm-search-binary":
|
||||
L := inputs.List
|
||||
x := inputs.SearchValue
|
||||
if L != nil && x != nil {
|
||||
_, err_case = algorithm_search_binary.FancyBinarySearch(*L, *x)
|
||||
} else {
|
||||
err_case = fmt.Errorf("Fehlende Inputs für Befehl '%[1]s'.", *problem.Command)
|
||||
}
|
||||
case "algorithm-search-interpolation":
|
||||
L := inputs.List
|
||||
x := inputs.SearchValue
|
||||
if L != nil && x != nil {
|
||||
_, err_case = algorithm_search_interpol.FancyInterpolationSearch(*L, *x, 0, len(*L)-1)
|
||||
} else {
|
||||
err_case = fmt.Errorf("Fehlende Inputs für Befehl '%[1]s'.", *problem.Command)
|
||||
}
|
||||
case "algorithm-search-ith-element":
|
||||
L := inputs.List
|
||||
i := inputs.SearchRank
|
||||
if L != nil && i != nil {
|
||||
_, err_case = algorithm_search_ith_element.FancyFindIthSmallest(*L, *i)
|
||||
} else {
|
||||
err_case = fmt.Errorf("Fehlende Inputs für Befehl '%[1]s'.", *problem.Command)
|
||||
}
|
||||
case "algorithm-search-ith-element-dc":
|
||||
L := inputs.List
|
||||
i := inputs.SearchRank
|
||||
if L != nil && i != nil {
|
||||
_, err_case = algorithm_search_ith_element.FancyFindIthSmallestDC(*L, *i)
|
||||
} else {
|
||||
err_case = fmt.Errorf("Fehlende Inputs für Befehl '%[1]s'.", *problem.Command)
|
||||
}
|
||||
case "algorithm-search-jump":
|
||||
L := inputs.List
|
||||
x := inputs.SearchValue
|
||||
m := inputs.JumpSize
|
||||
if L != nil && x != nil {
|
||||
_, err_case = algorithm_search_jump.FancyJumpSearchLinear(*L, *x, *m)
|
||||
} else {
|
||||
err_case = fmt.Errorf("Fehlende Inputs für Befehl '%[1]s'.", *problem.Command)
|
||||
}
|
||||
case "algorithm-search-jump-exp":
|
||||
L := inputs.List
|
||||
x := inputs.SearchValue
|
||||
if L != nil && x != nil {
|
||||
_, err_case = algorithm_search_jump.FancyJumpSearchExponentiell(*L, *x)
|
||||
} else {
|
||||
err_case = fmt.Errorf("Fehlende Inputs für Befehl '%[1]s'.", *problem.Command)
|
||||
}
|
||||
case "algorithm-search-poison":
|
||||
L := inputs.List
|
||||
if L != nil {
|
||||
_, err_case = algorithm_search_poison.FancyFindPoison(*L)
|
||||
} else {
|
||||
err_case = fmt.Errorf("Fehlende Inputs für Befehl '%[1]s'.", *problem.Command)
|
||||
}
|
||||
case "algorithm-search-poison-fast":
|
||||
L := inputs.List
|
||||
if L != nil {
|
||||
_, err_case = algorithm_search_poison.FancyFindPoisonFast(*L)
|
||||
} else {
|
||||
err_case = fmt.Errorf("Fehlende Inputs für Befehl '%[1]s'.", *problem.Command)
|
||||
}
|
||||
case "algorithm-search-sequential":
|
||||
L := inputs.List
|
||||
x := inputs.SearchValue
|
||||
if L != nil && x != nil {
|
||||
_, err_case = algorithm_search_sequential.FancySequentialSearch(*L, *x)
|
||||
} else {
|
||||
err_case = fmt.Errorf("Fehlende Inputs für Befehl '%[1]s'.", *problem.Command)
|
||||
}
|
||||
case "algorithm-sum-maxsub":
|
||||
L := inputs.List
|
||||
if L != nil {
|
||||
_, _, _, err_case = algorithm_sum_maxsubsum.FancyMaxSubSum(*L)
|
||||
} else {
|
||||
err_case = fmt.Errorf("Fehlende Inputs für Befehl '%[1]s'.", *problem.Command)
|
||||
}
|
||||
case "algorithm-sum-maxsub-dc":
|
||||
L := inputs.List
|
||||
if L != nil {
|
||||
_, _, _, err_case = algorithm_sum_maxsubsum.FancyMaxSubSumDC(*L)
|
||||
} else {
|
||||
err_case = fmt.Errorf("Fehlende Inputs für Befehl '%[1]s'.", *problem.Command)
|
||||
}
|
||||
default:
|
||||
err_case = fmt.Errorf("Unbekannter Befehl '%[1]s'.", *problem.Command)
|
||||
}
|
||||
}
|
||||
if err_case != nil {
|
||||
logging.LogError(err_case)
|
||||
}
|
||||
}
|
||||
setup.DisplayEndOfCase()
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user