startIterator() returns a new iterator on the given segmentStack. On success, the returned Iterator will be positioned so that Iterator.Current() will either provide the first entry in the iteration range or ErrIteratorDone. A startKeyInclusive of nil means the logical "bottom-most" possible key a
( startKeyInclusive, endKeyExclusive []byte, iteratorOptions IteratorOptions)
| 96 | // IteratorOptions.MinSegmentLevel parameter. For example, to ignore |
| 97 | // the lowest, 0th segment, use MinSegmentLevel of 1. |
| 98 | func (ss *segmentStack) startIterator( |
| 99 | startKeyInclusive, endKeyExclusive []byte, |
| 100 | iteratorOptions IteratorOptions) (*iterator, error) { |
| 101 | if iteratorOptions.MaxSegmentHeight <= 0 { |
| 102 | iteratorOptions.MaxSegmentHeight = len(ss.a) |
| 103 | } |
| 104 | |
| 105 | prefixLen := 0 |
| 106 | if len(startKeyInclusive) > 0 && |
| 107 | len(endKeyExclusive) > 0 { |
| 108 | prefixLen = sharedPrefixLen(startKeyInclusive, endKeyExclusive) |
| 109 | } |
| 110 | |
| 111 | iter := &iterator{ |
| 112 | ss: ss, |
| 113 | cursors: make([]*cursor, 0, len(ss.a)+1), |
| 114 | |
| 115 | startKeyInclusive: startKeyInclusive, |
| 116 | endKeyExclusive: endKeyExclusive, |
| 117 | |
| 118 | prefixLen: prefixLen, |
| 119 | |
| 120 | iteratorOptions: iteratorOptions, |
| 121 | } |
| 122 | |
| 123 | // ---------------------------------------------- |
| 124 | // Add cursors for our allowed segments. |
| 125 | |
| 126 | minSegmentLevel := iteratorOptions.MinSegmentLevel |
| 127 | maxSegmentLevel := iteratorOptions.MaxSegmentHeight - 1 |
| 128 | |
| 129 | ss.ensureSorted(minSegmentLevel, maxSegmentLevel) |
| 130 | |
| 131 | for ssIndex := minSegmentLevel; ssIndex <= maxSegmentLevel; ssIndex++ { |
| 132 | b := ss.a[ssIndex] |
| 133 | |
| 134 | sc, err := b.Cursor(startKeyInclusive, endKeyExclusive) |
| 135 | if err != nil { |
| 136 | return nil, err |
| 137 | } |
| 138 | op, k, v := sc.Current() |
| 139 | if op == 0 && k == nil && v == nil { |
| 140 | continue |
| 141 | } |
| 142 | |
| 143 | iter.cursors = append(iter.cursors, &cursor{ |
| 144 | ssIndex: ssIndex, |
| 145 | sc: sc, |
| 146 | op: op, |
| 147 | k: k, |
| 148 | v: v, |
| 149 | }) |
| 150 | } |
| 151 | |
| 152 | // ---------------------------------------------- |
| 153 | // Add cursor for the lower level, if wanted. |
| 154 | |
| 155 | if !iteratorOptions.SkipLowerLevel && |
no test coverage detected