github.com/zuoyebang/bitalostable@v1.0.1-0.20240229032404-e3b99a834294/internal/keyspan/internal_iter_shim.go (about) 1 // Copyright 2022 The LevelDB-Go and Pebble Authors. All rights reserved. Use 2 // of this source code is governed by a BSD-style license that can be found in 3 // the LICENSE file. 4 5 package keyspan 6 7 import "github.com/zuoyebang/bitalostable/internal/base" 8 9 // InternalIteratorShim is a temporary iterator type used as a shim between 10 // keyspan.MergingIter and base.InternalIterator. It's used temporarily for 11 // range deletions during compactions, allowing range deletions to be 12 // interleaved by a compaction input iterator. 13 // 14 // TODO(jackson): This type should be removed, and the usages converted to using 15 // an InterleavingIterator type that interleaves keyspan.Spans from a 16 // keyspan.FragmentIterator with point keys. 17 type InternalIteratorShim struct { 18 miter MergingIter 19 span *Span 20 iterKey base.InternalKey 21 } 22 23 // Assert that InternalIteratorShim implements InternalIterator. 24 var _ base.InternalIterator = &InternalIteratorShim{} 25 26 // Init initializes the internal iterator shim to merge the provided fragment 27 // iterators. 28 func (i *InternalIteratorShim) Init(cmp base.Compare, iters ...FragmentIterator) { 29 i.miter.Init(cmp, noopTransform, iters...) 30 } 31 32 // Span returns the span containing the full set of keys over the key span at 33 // the current iterator position. 34 func (i *InternalIteratorShim) Span() *Span { 35 return i.span 36 } 37 38 // SeekGE implements (base.InternalIterator).SeekGE. 39 func (i *InternalIteratorShim) SeekGE( 40 key []byte, flags base.SeekGEFlags, 41 ) (*base.InternalKey, []byte) { 42 panic("unimplemented") 43 } 44 45 // SeekPrefixGE implements (base.InternalIterator).SeekPrefixGE. 46 func (i *InternalIteratorShim) SeekPrefixGE( 47 prefix, key []byte, flags base.SeekGEFlags, 48 ) (*base.InternalKey, []byte) { 49 panic("unimplemented") 50 } 51 52 // SeekLT implements (base.InternalIterator).SeekLT. 53 func (i *InternalIteratorShim) SeekLT( 54 key []byte, flags base.SeekLTFlags, 55 ) (*base.InternalKey, []byte) { 56 panic("unimplemented") 57 } 58 59 // First implements (base.InternalIterator).First. 60 func (i *InternalIteratorShim) First() (*base.InternalKey, []byte) { 61 i.span = i.miter.First() 62 for i.span != nil && i.span.Empty() { 63 i.span = i.miter.Next() 64 } 65 if i.span == nil { 66 return nil, nil 67 } 68 i.iterKey = base.InternalKey{UserKey: i.span.Start, Trailer: i.span.Keys[0].Trailer} 69 return &i.iterKey, i.span.End 70 } 71 72 // Last implements (base.InternalIterator).Last. 73 func (i *InternalIteratorShim) Last() (*base.InternalKey, []byte) { 74 panic("unimplemented") 75 } 76 77 // Next implements (base.InternalIterator).Next. 78 func (i *InternalIteratorShim) Next() (*base.InternalKey, []byte) { 79 i.span = i.miter.Next() 80 for i.span != nil && i.span.Empty() { 81 i.span = i.miter.Next() 82 } 83 if i.span == nil { 84 return nil, nil 85 } 86 i.iterKey = base.InternalKey{UserKey: i.span.Start, Trailer: i.span.Keys[0].Trailer} 87 return &i.iterKey, i.span.End 88 } 89 90 // Prev implements (base.InternalIterator).Prev. 91 func (i *InternalIteratorShim) Prev() (*base.InternalKey, []byte) { 92 panic("unimplemented") 93 } 94 95 // Error implements (base.InternalIterator).Error. 96 func (i *InternalIteratorShim) Error() error { 97 return i.miter.Error() 98 } 99 100 // Close implements (base.InternalIterator).Close. 101 func (i *InternalIteratorShim) Close() error { 102 return i.miter.Close() 103 } 104 105 // SetBounds implements (base.InternalIterator).SetBounds. 106 func (i *InternalIteratorShim) SetBounds(lower, upper []byte) { 107 } 108 109 // String implements fmt.Stringer. 110 func (i *InternalIteratorShim) String() string { 111 return i.miter.String() 112 }