master > master: code go - messages verbessert

This commit is contained in:
RD 2021-11-05 15:44:06 +01:00
parent 38025247c7
commit 337790f3cd
2 changed files with 12 additions and 6 deletions

View File

@ -38,15 +38,14 @@ func InterpolationSearch(L []int, x int, u int, v int) int {
}
metrics.AddTimeCost()
p := getSuchposition(L, x, u, v)
logging.Debug("Interpolante von x in (u, v)=(%[1]v, %[2]v) ist p = %[3]v.", u, v, p)
if L[p] == x {
logging.Debug("x in Position p gefunden")
logging.Debug("Interpolante in (%[1]v, %[2]v) ist p = %[3]v; L[p] == x; ===> Element gefunden", u, v, p)
return p
} else if x < L[p] {
logging.Debug("Suche in linker Hälfte fortsetzen.")
logging.Debug("Interpolante in (%[1]v, %[2]v) ist p = %[3]v; L[p] > x; ===> suche in linker Hälfte", u, v, p)
return InterpolationSearch(L, x, u, p-1)
} else { // } else if x > L[p] {
logging.Debug("Suche in rechter Hälfte fortsetzen.")
logging.Debug("Interpolante in (%[1]v, %[2]v) ist p = %[3]v; L[p] < x; ===> suche in rechter Hälfte", u, v, p)
return InterpolationSearch(L, x, p+1, v)
}
}

View File

@ -103,8 +103,8 @@ func DisplayEndOfAlgorithm(outputs map[string]interface{}) {
func DisplayMetrics() {
// logging.Plain("Dauer der Ausführung: t = \033[1m%[1]v\033[0m", metrics.GetTimeElapsed())
logging.Plain("Dauer der Ausführung: t = \033[1m%[1]v\033[0m", metrics.GetTimeElapsedLongFormat())
logging.Plain("Kosten (Zeit): T(n) = \033[1m%[1]v\033[0m", metrics.GetTimeCost())
logging.Plain("Kosten (Platz): S(n) = \033[1m%[1]v\033[0m", metrics.GetSpaceCost())
logging.Plain("Kosten (Zeit): T(n) = \033[1m%[1]v\033[0m", displayCost(metrics.GetTimeCost()))
logging.Plain("Kosten (Platz): S(n) = \033[1m%[1]v\033[0m", displayCost(metrics.GetSpaceCost()))
return
}
@ -120,3 +120,10 @@ func DisplayBar(options ...int) {
logging.Plain("+%[1]s+", strings.Repeat("-", n))
return
}
func displayCost(cost int) string {
if cost > 0 {
return fmt.Sprintf("%v", cost)
}
return "-"
}