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

Method _find

texteditor/difflib/bytes/bytes.go:82–107  ·  view source on GitHub ↗
(line *[]byte)

Source from the content-addressed store, hash-verified

80)
81
82func (b2j *B2J) _find(line *[]byte) (h lineHash, slotIndex int,
83 slot []int, lt lineType) {
84 h = _hash(*line)
85 for slotIndex, slot = range b2j.store[h] {
86 // Thanks to the qualities of sha1, the probability of having more than
87 // one line content with the same hash is very low. Nevertheless, store
88 // each of them in a different slot, that we can differentiate by
89 // looking at the line contents in the b slice.
90 // In place of all the line numbers where the line appears, a slot can
91 // also contain [lineno, -1] if b[lineno] is junk.
92 if bytes.Equal(*line, b2j.b[slot[0]]) {
93 // The content already has a slot in its hash bucket.
94 if len(slot) == 2 && slot[1] < 0 {
95 lt = lineType(slot[1])
96 } else {
97 lt = lineNORMAL
98 }
99 return // every return variable has the correct value
100 }
101 }
102 // The line content still has no slot.
103 slotIndex = -1
104 slot = nil
105 lt = lineNONE
106 return
107}
108
109func newB2J(b [][]byte, isJunk func([]byte) bool, autoJunk bool) *B2J {
110 b2j := B2J{store: map[lineHash][][]int{}, b: b}

Callers 3

newB2JFunction · 0.95
getMethod · 0.95
isBJunkMethod · 0.95

Calls 3

_hashFunction · 0.85
lineTypeTypeAlias · 0.85
EqualMethod · 0.80

Tested by

no test coverage detected