| 107 | } |
| 108 | |
| 109 | func 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 | |
| 136 | func (b2j *B2J) get(line []byte) []int { |
| 137 | _, _, slot, lt := b2j._find(&line) |