MCPcopy Create free account
hub / github.com/couchbase/moss / buildIndex

Method buildIndex

segment.go:763–804  ·  view source on GitHub ↗

------------------------------------------------------ Builds and initializes the in-memory index for the segment.

(quota int, minKeyBytes int)

Source from the content-addressed store, hash-verified

761
762// Builds and initializes the in-memory index for the segment.
763func (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

Callers 1

doLoadSegmentsMethod · 0.80

Calls 5

LenMethod · 0.95
currentKeyMethod · 0.95
nextDeltaMethod · 0.95
newSegmentKeysIndexFunction · 0.85
addMethod · 0.80

Tested by

no test coverage detected