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

Function newB2J

texteditor/difflib/bytes/bytes.go:109–134  ·  view source on GitHub ↗
(b [][]byte, isJunk func([]byte) bool, autoJunk bool)

Source from the content-addressed store, hash-verified

107}
108
109func newB2J(b [][]byte, isJunk func([]byte) bool, autoJunk bool) *B2J {
110 b2j := B2J{store: map[lineHash][][]int{}, b: b}
111 ntest := len(b)
112 if autoJunk && ntest >= 200 {
113 ntest = ntest/100 + 1
114 }
115 for lineno, line := range b {
116 h, slotIndex, slot, lt := b2j._find(&line)
117 switch lt {
118 case lineNORMAL:
119 if len(slot) >= ntest {
120 b2j.store[h][slotIndex] = []int{slot[0], int(linePOPULAR)}
121 } else {
122 b2j.store[h][slotIndex] = append(slot, lineno)
123 }
124 case lineNONE:
125 if isJunk != nil && isJunk(line) {
126 b2j.store[h] = append(b2j.store[h], []int{lineno, int(lineJUNK)})
127 } else {
128 b2j.store[h] = append(b2j.store[h], []int{lineno})
129 }
130 default:
131 }
132 }
133 return &b2j
134}
135
136func (b2j *B2J) get(line []byte) []int {
137 _, _, slot, lt := b2j._find(&line)

Callers 1

chainBMethod · 0.85

Calls 1

_findMethod · 0.95

Tested by

no test coverage detected