@@ -23,7 +23,7 @@ import (
23
23
"io"
24
24
"strings"
25
25
"unicode"
26
- "crypto/sha1 "
26
+ "hash/adler32 "
27
27
)
28
28
29
29
func min (a , b int ) int {
@@ -69,22 +69,23 @@ type OpCode struct {
69
69
J2 int
70
70
}
71
71
72
- func _hash (line []byte ) int32 {
73
- h := sha1 .Sum (line )
74
- return int32 (h [0 ]) << 3 * 8 + int32 (h [1 ]) << 2 * 8 + int32 (h [2 ]) << 1 * 8 + int32 (h [3 ])
72
+ type lineHash uint32
73
+
74
+ func _hash (line []byte ) lineHash {
75
+ return lineHash (adler32 .Checksum (line ))
75
76
}
76
77
77
78
// This is essentially a map from lines to line numbers, so that later it can
78
79
// be made a bit cleverer than the standard map in that it will not need to
79
80
// store copies of the lines.
80
81
// It needs to hold a reference to the underlying slice of lines.
81
82
type B2J struct {
82
- store map [int32 ] [][]int
83
+ store map [lineHash ] [][]int
83
84
b [][]byte
84
85
}
85
86
86
87
func newB2J (b [][]byte ) * B2J {
87
- b2j := B2J {store : map [int32 ] [][]int {}, b : b }
88
+ b2j := B2J {store : map [lineHash ] [][]int {}, b : b }
88
89
for lineno , line := range b {
89
90
h := _hash (line )
90
91
// Thanks to the qualities of sha1, the probability of having more than
@@ -129,7 +130,7 @@ func (b2j *B2J) delete(line []byte) {
129
130
}
130
131
}
131
132
132
- func (b2j * B2J ) deleteHash (h int32 ) {
133
+ func (b2j * B2J ) deleteHash (h lineHash ) {
133
134
delete (b2j .store , h )
134
135
}
135
136
@@ -173,9 +174,9 @@ type SequenceMatcher struct {
173
174
b2j B2J
174
175
IsJunk func ([]byte ) bool
175
176
autoJunk bool
176
- bJunk map [int32 ]struct {}
177
+ bJunk map [lineHash ]struct {}
177
178
matchingBlocks []Match
178
- fullBCount map [int32 ]int
179
+ fullBCount map [lineHash ]int
179
180
bPopular []int
180
181
opCodes []OpCode
181
182
}
@@ -236,7 +237,7 @@ func (m *SequenceMatcher) chainB() {
236
237
b2j := * newB2J (m .b )
237
238
238
239
// Purge junk elements
239
- m .bJunk = map [int32 ]struct {}{}
240
+ m .bJunk = map [lineHash ]struct {}{}
240
241
if m .IsJunk != nil {
241
242
junk := m .bJunk
242
243
b2j .iter (func (s []byte , _ []int ){
@@ -560,7 +561,7 @@ func (m *SequenceMatcher) QuickRatio() float64 {
560
561
// greater due hash collisions incurring false positives, but
561
562
// we don't care because we want an upper bound anyway.
562
563
if m .fullBCount == nil {
563
- m .fullBCount = map [int32 ]int {}
564
+ m .fullBCount = map [lineHash ]int {}
564
565
for _ , s := range m .b {
565
566
h := _hash (s )
566
567
m .fullBCount [h ] = m .fullBCount [h ] + 1
@@ -569,7 +570,7 @@ func (m *SequenceMatcher) QuickRatio() float64 {
569
570
570
571
// avail[x] is the number of times x appears in 'b' less the
571
572
// number of times we've seen it in 'a' so far ... kinda
572
- avail := map [int32 ]int {}
573
+ avail := map [lineHash ]int {}
573
574
matches := 0
574
575
for _ , s := range m .a {
575
576
h := _hash (s )
0 commit comments