summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2017-08-20 03:51:53 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2017-08-20 12:29:11 +0900
commit6aae12288e4a72818d8efb60b85b7d34330b414e (patch)
treeee9f3da03c70042d6877b46a330553a31018fa62
parent302cc552efd6c48e3abd04c2077df3b8ce7356af (diff)
downloadfzf-6aae12288e4a72818d8efb60b85b7d34330b414e.tar.gz
Extract debug code from FuzzyMatchV2
-rw-r--r--src/algo/algo.go61
1 files changed, 35 insertions, 26 deletions
diff --git a/src/algo/algo.go b/src/algo/algo.go
index 8701d30e..168dd919 100644
--- a/src/algo/algo.go
+++ b/src/algo/algo.go
@@ -302,6 +302,38 @@ func asciiFuzzyIndex(input *util.Chars, pattern []rune, caseSensitive bool) int
return firstIdx
}
+func debugV2(T []rune, pattern []rune, F []int32, lastIdx int, H []int16, C []int16) {
+ width := lastIdx - int(F[0]) + 1
+
+ for i, f := range F {
+ I := i * width
+ if i == 0 {
+ fmt.Print(" ")
+ for j := int(f); j <= lastIdx; j++ {
+ fmt.Printf(" " + string(T[j]) + " ")
+ }
+ fmt.Println()
+ }
+ fmt.Print(string(pattern[i]) + " ")
+ for idx := int(F[0]); idx < int(f); idx++ {
+ fmt.Print(" 0 ")
+ }
+ for idx := int(f); idx <= lastIdx; idx++ {
+ fmt.Printf("%2d ", H[i*width+idx-int(F[0])])
+ }
+ fmt.Println()
+
+ fmt.Print(" ")
+ for idx, p := range C[I : I+width] {
+ if idx+int(F[0]) < int(F[i]) {
+ p = 0
+ }
+ fmt.Printf("%2d ", p)
+ }
+ fmt.Println()
+ }
+}
+
func FuzzyMatchV2(caseSensitive bool, normalize bool, forward bool, input *util.Chars, pattern []rune, withPos bool, slab *util.Slab) (Result, *[]int) {
// Assume that pattern is given in lowercase if case-insensitive.
// First check if there's a match and calculate bonus for each position.
@@ -448,33 +480,10 @@ func FuzzyMatchV2(caseSensitive bool, normalize bool, forward bool, input *util.
}
H[I+j0] = score
}
+ }
- if DEBUG {
- if i == 0 {
- fmt.Print(" ")
- for j := int(F[i]); j <= lastIdx; j++ {
- fmt.Printf(" " + string(T[j]) + " ")
- }
- fmt.Println()
- }
- fmt.Print(string(pattern[i]) + " ")
- for idx := int(F[0]); idx < int(F[i]); idx++ {
- fmt.Print(" 0 ")
- }
- for idx := int(F[i]); idx <= lastIdx; idx++ {
- fmt.Printf("%2d ", H[i*width+idx-int(F[0])])
- }
- fmt.Println()
-
- fmt.Print(" ")
- for idx, p := range C[I : I+width] {
- if idx+int(F[0]) < int(F[i]) {
- p = 0
- }
- fmt.Printf("%2d ", p)
- }
- fmt.Println()
- }
+ if DEBUG {
+ debugV2(T, pattern, F, lastIdx, H, C)
}
// Phase 4. (Optional) Backtrace to find character positions