MCPcopy Create free account
hub / github.com/cogentcore/core / GetOpCodes

Method GetOpCodes

texteditor/difflib/difflib.go:378–412  ·  view source on GitHub ↗

GetOpCodes returns a list of 5-tuples describing how to turn a into b. Each tuple is of the form (tag, i1, i2, j1, j2). The first tuple has i1 == j1 == 0, and remaining tuples have i1 == the i2 from the tuple preceding it, and likewise for j1 == the previous j2. The tags are characters, with thes

()

Source from the content-addressed store, hash-verified

376//
377// 'e' (equal): a[i1:i2] == b[j1:j2]
378func (m *SequenceMatcher) GetOpCodes() []OpCode {
379 if m.opCodes != nil {
380 return m.opCodes
381 }
382 i, j := 0, 0
383 matching := m.GetMatchingBlocks()
384 opCodes := make([]OpCode, 0, len(matching))
385 for _, m := range matching {
386 // invariant: we've pumped out correct diffs to change
387 // a[:i] into b[:j], and the next matching block is
388 // a[ai:ai+size] == b[bj:bj+size]. So we need to pump
389 // out a diff to change a[i:ai] into b[j:bj], pump out
390 // the matching block, and move (i,j) beyond the match
391 ai, bj, size := m.A, m.B, m.Size
392 tag := byte(0)
393 if i < ai && j < bj {
394 tag = 'r'
395 } else if i < ai {
396 tag = 'd'
397 } else if j < bj {
398 tag = 'i'
399 }
400 if tag > 0 {
401 opCodes = append(opCodes, OpCode{tag, i, ai, j, bj})
402 }
403 i, j = ai+size, bj+size
404 // the list of matching blocks is terminated by a
405 // sentinel with size 0
406 if size > 0 {
407 opCodes = append(opCodes, OpCode{'e', ai, i, bj, j})
408 }
409 }
410 m.opCodes = opCodes
411 return m.opCodes
412}
413
414// GetGroupedOpCodes isolates change clusters by eliminating ranges with no changes.
415//

Callers 8

GetGroupedOpCodesMethod · 0.95
TestGetOptCodesFunction · 0.45
TestWithAsciiOneInsertFunction · 0.45
TestWithAsciiOnDeleteFunction · 0.45
BenchmarkMatcherFunction · 0.45
CompareMethod · 0.45
FancyReplaceMethod · 0.45
DiffLinesFunction · 0.45

Calls 1

GetMatchingBlocksMethod · 0.95

Tested by 4

TestGetOptCodesFunction · 0.36
TestWithAsciiOneInsertFunction · 0.36
TestWithAsciiOnDeleteFunction · 0.36
BenchmarkMatcherFunction · 0.36