master > master: code go - vereinfachte logging
This commit is contained in:
@@ -5,8 +5,6 @@ package binary
|
||||
* ---------------------------------------------------------------- */
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"ads/internal/core/logging"
|
||||
"ads/internal/core/metrics"
|
||||
)
|
||||
@@ -30,20 +28,20 @@ Outputs: Position von x in L, sonst −1 wenn x nicht in L.
|
||||
*/
|
||||
func BinarySearch(L []int, x int) int {
|
||||
if len(L) == 0 {
|
||||
logging.LogDebug(fmt.Sprintf("x nicht in L"))
|
||||
logging.Debug("x nicht in L")
|
||||
return -1
|
||||
}
|
||||
metrics.AddTimeCost()
|
||||
m := int(len(L) / 2)
|
||||
if L[m] == x {
|
||||
logging.LogDebug(fmt.Sprintf("x in Position m gefunden"))
|
||||
logging.Debug("x in Position m gefunden")
|
||||
return m
|
||||
} else if x < L[m] {
|
||||
logging.LogDebug(fmt.Sprintf("Suche in linker Hälfte fortsetzen."))
|
||||
logging.Debug("Suche in linker Hälfte fortsetzen.")
|
||||
index := BinarySearch(L[:m], x)
|
||||
return index
|
||||
} else { // } else if x > L[m] {
|
||||
logging.LogDebug(fmt.Sprintf("Suche in rechter Hälfte fortsetzen."))
|
||||
logging.Debug("Suche in rechter Hälfte fortsetzen.")
|
||||
index := BinarySearch(L[m+1:], x)
|
||||
if index >= 0 {
|
||||
index += (m + 1) // NOTE: muss Indexwert kompensieren
|
||||
|
||||
Reference in New Issue
Block a user