-
Notifications
You must be signed in to change notification settings - Fork 0
/
dawgutils.go
75 lines (63 loc) · 1.5 KB
/
dawgutils.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
64
65
66
67
68
69
70
71
72
73
74
75
package graph
import (
"fmt"
"hash/fnv"
)
const (
SHANotMatchingError = "Graph does not match advertised hash."
DeserializationError = "Graph deserialization error, or mismatching library version"
QuickCreateError = "Cannot create QuickDawg from Dawg"
CompactingError = "Cannot compact QuickDawg"
)
/*
** Package level global variables
*/
var NextId int = -1
var pld PackageLevelRandomDebugger
var pDBP PlaceholderDBP
var loggingEnabled = true
func SetLoggingEnabled(b bool) {
loggingEnabled = b
}
func log(format string, args ...interface{}) {
if loggingEnabled == true {
fmt.Printf(format, args...)
}
}
func minLength(a, b string) (ret int) {
ret = len(a)
if len(b) < len(a) {
ret = len(b)
}
return
}
func calcHash(in []byte) uint32 {
hash := fnv.New32a()
hash.Write(in)
return hash.Sum32()
}
/*
** Interface for debugging
*/
type PackageLevelRandomDebugger interface {
OnDebug(message string)
}
type ResultItem struct {
word string
value int
}
// DawgBinaryParser - Interface specifically created for graph deserialization status callbacks
type DawgBinaryParser interface {
OnCompleted(d *Dawg)
OnFailed(cause string)
OnDebug(message string)
}
// PlaceholderDBP - Placeholder debugging struct implementing DBP methods for local debugging
type PlaceholderDBP struct{}
func (p PlaceholderDBP) OnCompleted(d *Dawg) {}
func (p PlaceholderDBP) OnFailed(cause string) {
log("DBP ERROR :: %s\n", cause)
}
func (p PlaceholderDBP) OnDebug(message string) {
log("DBP DEBUG :: %s\n", message)
}