-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdebug.go
63 lines (50 loc) · 1.27 KB
/
debug.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// +build debug
package skiprope
import (
"fmt"
"log"
"os"
"strings"
"sync/atomic"
)
const DEBUG = true
var TABCOUNT uint32
var TRACK = false
var _logger_ = log.New(os.Stderr, "", 0)
var replacement = "\n"
func tabcount() int {
return int(atomic.LoadUint32(&TABCOUNT))
}
func enterLoggingContext() {
atomic.AddUint32(&TABCOUNT, 1)
tabcount := tabcount()
_logger_.SetPrefix(strings.Repeat("\t", tabcount))
replacement = "\n" + strings.Repeat("\t", tabcount)
}
func leaveLoggingContext() {
tabcount := tabcount()
tabcount--
if tabcount < 0 {
atomic.StoreUint32(&TABCOUNT, 0)
tabcount = 0
} else {
atomic.StoreUint32(&TABCOUNT, uint32(tabcount))
}
_logger_.SetPrefix(strings.Repeat("\t", tabcount))
replacement = "\n" + strings.Repeat("\t", tabcount)
}
func logf(format string, others ...interface{}) {
if DEBUG {
// format = strings.Replace(format, "\n", replacement, -1)
s := fmt.Sprintf(format, others...)
s = strings.Replace(s, "\n", replacement, -1)
_logger_.Println(s)
// _logger_.Printf(format, others...)
}
}
func (k knot) GoString() string {
return fmt.Sprintf("Data: %q | (Height %d, Used %d) | %v", string(k.data[:]), k.height, k.used, k.nexts)
}
func (s skipknot) GoString() string {
return fmt.Sprintf("%#v | skipped %v", s.knot, s.skipped)
}