------------------------------------------------------ Builds and initializes the in-memory index for the segment.
(quota int, minKeyBytes int)
| 761 | |
| 762 | // Builds and initializes the in-memory index for the segment. |
| 763 | func (a *segment) buildIndex(quota int, minKeyBytes int) { |
| 764 | if int(a.totKeyByte) < minKeyBytes { |
| 765 | // Build the index only if the total key bytes is greater |
| 766 | // than or equal to the SegmentKeysIndexMinKeyBytes. |
| 767 | return |
| 768 | } |
| 769 | |
| 770 | keyCount := a.Len() |
| 771 | if keyCount == 0 { |
| 772 | return // No keys to index. |
| 773 | } |
| 774 | |
| 775 | keyAvgSize := int(a.totKeyByte) / keyCount |
| 776 | |
| 777 | sindex := newSegmentKeysIndex(quota, keyCount, keyAvgSize) |
| 778 | if sindex == nil { |
| 779 | return |
| 780 | } |
| 781 | |
| 782 | scursor := &segmentCursor{ |
| 783 | s: a, |
| 784 | end: a.Len(), |
| 785 | } |
| 786 | |
| 787 | for { |
| 788 | keyIdx, key := scursor.currentKey() |
| 789 | if key == nil { |
| 790 | break |
| 791 | } |
| 792 | |
| 793 | if !sindex.add(keyIdx, key) { |
| 794 | break // Out of space. |
| 795 | } |
| 796 | |
| 797 | err := scursor.nextDelta(sindex.hop) |
| 798 | if err != nil { |
| 799 | break |
| 800 | } |
| 801 | } |
| 802 | |
| 803 | a.index = sindex |
| 804 | } |
| 805 | |
| 806 | // ------------------------------------------------------ |
| 807 |
no test coverage detected