@@ -9,21 +9,21 @@ import "context"
99const MaxChainLen = 63
1010
1111type histogram [E comparable ] struct {
12- tokenOccurances map [E ][]int
12+ tokenOccurrences map [E ][]int
1313}
1414
1515func (h * histogram [E ]) populate (a []E ) {
1616 for i , e := range a {
17- if p , ok := h .tokenOccurances [e ]; ok {
18- h .tokenOccurances [e ] = append (p , i )
17+ if p , ok := h .tokenOccurrences [e ]; ok {
18+ h .tokenOccurrences [e ] = append (p , i )
1919 continue
2020 }
21- h .tokenOccurances [e ] = []int {i }
21+ h .tokenOccurrences [e ] = []int {i }
2222 }
2323}
2424
25- func (h * histogram [E ]) numTokenOccurances (e E ) int {
26- if p , ok := h .tokenOccurances [e ]; ok {
25+ func (h * histogram [E ]) numTokenOccurrences (e E ) int {
26+ if p , ok := h .tokenOccurrences [e ]; ok {
2727 return len (p )
2828 }
2929 return 0
@@ -32,7 +32,7 @@ func (h *histogram[E]) numTokenOccurances(e E) int {
3232func (h * histogram [E ]) clear () {
3333 // runtime: clear() is slow for maps with big capacity and small number of items
3434 // https://github.com/golang/go/issues/70617
35- h .tokenOccurances = make (map [E ][]int )
35+ h .tokenOccurrences = make (map [E ][]int )
3636}
3737
3838type Lcs struct {
@@ -51,7 +51,7 @@ func (s *LcsSearch[E]) run(before, after []E, h *histogram[E]) {
5151 pos := 0
5252 for pos < len (after ) {
5353 e := after [pos ]
54- if num := h .numTokenOccurances (e ); num != 0 {
54+ if num := h .numTokenOccurrences (e ); num != 0 {
5555 s .foundCS = true
5656 if num <= s .minOccurrences {
5757 pos = s .updateLcs (before , after , pos , e , h )
@@ -65,12 +65,12 @@ func (s *LcsSearch[E]) run(before, after []E, h *histogram[E]) {
6565
6666func (s * LcsSearch [E ]) updateLcs (before , after []E , afterPos int , token E , h * histogram [E ]) int {
6767 nextTokenIndex2 := afterPos + 1
68- tokenOccurances := h .tokenOccurances [token ]
69- tokenIndex1 := tokenOccurances [0 ]
68+ tokenOccurrences := h .tokenOccurrences [token ]
69+ tokenIndex1 := tokenOccurrences [0 ]
7070 pos := 1
71- occurancesIter :
71+ occurrencesIter :
7272 for {
73- occurances := h .numTokenOccurances (token )
73+ occurrences := h .numTokenOccurrences (token )
7474 s1 , s2 := tokenIndex1 , afterPos
7575 for {
7676 if s1 == 0 || s2 == 0 {
@@ -82,8 +82,8 @@ occurancesIter:
8282 }
8383 s1 --
8484 s2 --
85- newOcurances := h .numTokenOccurances (t1 )
86- occurances = min (newOcurances , occurances )
85+ newOccurrences := h .numTokenOccurrences (t1 )
86+ occurrences = min (newOccurrences , occurrences )
8787 }
8888 e1 , e2 := tokenIndex1 + 1 , afterPos + 1
8989 for {
@@ -94,28 +94,28 @@ occurancesIter:
9494 if t1 != t2 {
9595 break
9696 }
97- newOccuraces := h .numTokenOccurances (t1 )
98- occurances = min (occurances , newOccuraces )
97+ newOccurrences := h .numTokenOccurrences (t1 )
98+ occurrences = min (occurrences , newOccurrences )
9999 e1 ++
100100 e2 ++
101101 }
102102 if nextTokenIndex2 < e2 {
103103 nextTokenIndex2 = e2
104104 }
105105 length := e2 - s2
106- if s .lcs .length < length || s .minOccurrences > occurances {
107- s .minOccurrences = occurances
106+ if s .lcs .length < length || s .minOccurrences > occurrences {
107+ s .minOccurrences = occurrences
108108 s .lcs = Lcs {
109109 beforeStart : s1 ,
110110 afterStart : s2 ,
111111 length : length ,
112112 }
113113 }
114114 for {
115- if pos >= len (tokenOccurances ) {
116- break occurancesIter
115+ if pos >= len (tokenOccurrences ) {
116+ break occurrencesIter
117117 }
118- nextTokenIndex := tokenOccurances [pos ]
118+ nextTokenIndex := tokenOccurrences [pos ]
119119 pos ++
120120 if nextTokenIndex > e2 {
121121 tokenIndex1 = nextTokenIndex
@@ -145,42 +145,42 @@ type changesOut struct {
145145 changes []Change
146146}
147147
148- func (h * histogram [E ]) run (ctx context.Context , beforce []E , beforePos int , after []E , afterPos int , o * changesOut ) error {
148+ func (h * histogram [E ]) run (ctx context.Context , before []E , beforePos int , after []E , afterPos int , o * changesOut ) error {
149149 for {
150150 select {
151151 case <- ctx .Done ():
152152 return ctx .Err ()
153153 default :
154154 }
155- if len (beforce ) == 0 {
155+ if len (before ) == 0 {
156156 if len (after ) != 0 {
157157 o .changes = append (o .changes , Change {P1 : beforePos , P2 : afterPos , Ins : len (after )})
158158 }
159159 return nil
160160 }
161161 if len (after ) == 0 {
162- o .changes = append (o .changes , Change {P1 : beforePos , P2 : afterPos , Del : len (beforce )})
162+ o .changes = append (o .changes , Change {P1 : beforePos , P2 : afterPos , Del : len (before )})
163163 return nil
164164 }
165- h .populate (beforce )
166- lcs := findLcs (beforce , after , h )
165+ h .populate (before )
166+ lcs := findLcs (before , after , h )
167167 if lcs == nil {
168- changes , err := onpCompute (ctx , beforce , beforePos , after , afterPos )
168+ changes , err := onpCompute (ctx , before , beforePos , after , afterPos )
169169 if err != nil {
170170 return err
171171 }
172172 o .changes = append (o .changes , changes ... )
173173 return nil
174174 }
175175 if lcs .length == 0 {
176- o .changes = append (o .changes , Change {P1 : beforePos , P2 : afterPos , Del : len (beforce ), Ins : len (after )})
176+ o .changes = append (o .changes , Change {P1 : beforePos , P2 : afterPos , Del : len (before ), Ins : len (after )})
177177 return nil
178178 }
179- if err := h .run (ctx , beforce [:lcs .beforeStart ], beforePos , after [:lcs .afterStart ], afterPos , o ); err != nil {
179+ if err := h .run (ctx , before [:lcs .beforeStart ], beforePos , after [:lcs .afterStart ], afterPos , o ); err != nil {
180180 return err
181181 }
182182 e1 := lcs .beforeStart + lcs .length
183- beforce = beforce [e1 :]
183+ before = before [e1 :]
184184 beforePos += e1
185185 e2 := lcs .afterStart + lcs .length
186186 after = after [e2 :]
@@ -197,7 +197,7 @@ func HistogramDiff[E comparable](ctx context.Context, L1, L2 []E) ([]Change, err
197197 L1 = L1 [:len (L1 )- suffix ]
198198 L2 = L2 [:len (L2 )- suffix ]
199199 h := & histogram [E ]{
200- tokenOccurances : make (map [E ][]int , len (L1 )),
200+ tokenOccurrences : make (map [E ][]int , len (L1 )),
201201 }
202202 o := & changesOut {changes : make ([]Change , 0 , 100 )}
203203 if err := h .run (ctx , L1 , prefix , L2 , prefix , o ); err != nil {
0 commit comments