github.com/cockroachdb/pebble@v1.1.1-0.20240513155919-3622ade60459/internal/arenaskl/flush_iterator.go (about) 1 /* 2 * Copyright 2017 Dgraph Labs, Inc. and Contributors 3 * Modifications copyright (C) 2017 Andy Kimball and Contributors 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package arenaskl 19 20 import "github.com/cockroachdb/pebble/internal/base" 21 22 // flushIterator is an iterator over the skiplist object. Use Skiplist.NewFlushIter 23 // to construct an iterator. The current state of the iterator can be cloned by 24 // simply value copying the struct. 25 type flushIterator struct { 26 Iterator 27 bytesIterated *uint64 28 } 29 30 // flushIterator implements the base.InternalIterator interface. 31 var _ base.InternalIterator = (*flushIterator)(nil) 32 33 func (it *flushIterator) String() string { 34 return "memtable" 35 } 36 37 func (it *flushIterator) SeekGE( 38 key []byte, flags base.SeekGEFlags, 39 ) (*base.InternalKey, base.LazyValue) { 40 panic("pebble: SeekGE unimplemented") 41 } 42 43 func (it *flushIterator) SeekPrefixGE( 44 prefix, key []byte, flags base.SeekGEFlags, 45 ) (*base.InternalKey, base.LazyValue) { 46 panic("pebble: SeekPrefixGE unimplemented") 47 } 48 49 func (it *flushIterator) SeekLT( 50 key []byte, flags base.SeekLTFlags, 51 ) (*base.InternalKey, base.LazyValue) { 52 panic("pebble: SeekLT unimplemented") 53 } 54 55 // First seeks position at the first entry in list. Returns the key and value 56 // if the iterator is pointing at a valid entry, and (nil, nil) otherwise. Note 57 // that First only checks the upper bound. It is up to the caller to ensure 58 // that key is greater than or equal to the lower bound. 59 func (it *flushIterator) First() (*base.InternalKey, base.LazyValue) { 60 key, val := it.Iterator.First() 61 if key == nil { 62 return nil, base.LazyValue{} 63 } 64 *it.bytesIterated += uint64(it.nd.allocSize) 65 return key, val 66 } 67 68 // Next advances to the next position. Returns the key and value if the 69 // iterator is pointing at a valid entry, and (nil, nil) otherwise. 70 // Note: flushIterator.Next mirrors the implementation of Iterator.Next 71 // due to performance. Keep the two in sync. 72 func (it *flushIterator) Next() (*base.InternalKey, base.LazyValue) { 73 it.nd = it.list.getNext(it.nd, 0) 74 if it.nd == it.list.tail { 75 return nil, base.LazyValue{} 76 } 77 it.decodeKey() 78 *it.bytesIterated += uint64(it.nd.allocSize) 79 return &it.key, base.MakeInPlaceValue(it.value()) 80 } 81 82 func (it *flushIterator) NextPrefix(succKey []byte) (*base.InternalKey, base.LazyValue) { 83 panic("pebble: NextPrefix unimplemented") 84 } 85 86 func (it *flushIterator) Prev() (*base.InternalKey, base.LazyValue) { 87 panic("pebble: Prev unimplemented") 88 }