-
-
Notifications
You must be signed in to change notification settings - Fork 250
/
structs.go
89 lines (77 loc) · 1.72 KB
/
structs.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package processor
import (
"bytes"
"sync"
)
type Language struct {
LineComment []string `json:"line_comment"`
ComplexityChecks []string `json:"complexitychecks"`
Extensions []string `json:"extensions"`
MultiLine [][]string `json:"multi_line"`
Quotes [][]string `json:"quotes"`
}
type LanguageFeature struct {
ComplexityChecks [][]byte
ComplexityBytes []byte
SingleLineComment [][]byte
MultiLineComment []OpenClose
StringChecks []OpenClose
}
type FileJob struct {
Language string
Filename string
Extension string
Location string
Content []byte
Bytes int64
Lines int64
Code int64
Comment int64
Blank int64
Complexity int64
WeightedComplexity float64
Hash []byte
}
type LanguageSummary struct {
Name string
Bytes int64
Lines int64
Code int64
Comment int64
Blank int64
Complexity int64
Count int64
WeightedComplexity float64
Files []*FileJob
}
type OpenClose struct {
Open []byte
Close []byte
}
type CheckDuplicates struct {
hashes map[int64][][]byte
mux sync.Mutex
}
func (c *CheckDuplicates) Add(key int64, hash []byte) {
c.mux.Lock()
defer c.mux.Unlock()
hashes, ok := c.hashes[key]
if ok {
c.hashes[key] = append(hashes, hash)
} else {
c.hashes[key] = [][]byte{hash}
}
}
func (c *CheckDuplicates) Check(key int64, hash []byte) bool {
c.mux.Lock()
defer c.mux.Unlock()
hashes, ok := c.hashes[key]
if ok {
for _, h := range hashes {
if bytes.Equal(h, hash) {
return true
}
}
}
return false
}