github.com/zuoyebang/bitalostable@v1.0.1-0.20240229032404-e3b99a834294/internal_test.go (about) 1 // Copyright 2019 The LevelDB-Go and Pebble and Bitalostored 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 bitalostable 6 7 import "github.com/zuoyebang/bitalostable/internal/base" 8 9 // internalIterAdapter adapts the new internalIterator interface which returns 10 // the key and value from positioning methods (Seek*, First, Last, Next, Prev) 11 // to the old interface which returned a boolean corresponding to Valid. Only 12 // used by test code. 13 type internalIterAdapter struct { 14 internalIterator 15 key *InternalKey 16 val []byte 17 } 18 19 func newInternalIterAdapter(iter internalIterator) *internalIterAdapter { 20 return &internalIterAdapter{ 21 internalIterator: iter, 22 } 23 } 24 25 func (i *internalIterAdapter) update(key *InternalKey, val []byte) bool { 26 i.key = key 27 i.val = val 28 return i.key != nil 29 } 30 31 func (i *internalIterAdapter) String() string { 32 return "internal-iter-adapter" 33 } 34 35 func (i *internalIterAdapter) SeekGE(key []byte, flags base.SeekGEFlags) bool { 36 return i.update(i.internalIterator.SeekGE(key, flags)) 37 } 38 39 func (i *internalIterAdapter) SeekPrefixGE(prefix, key []byte, flags base.SeekGEFlags) bool { 40 return i.update(i.internalIterator.SeekPrefixGE(prefix, key, flags)) 41 } 42 43 func (i *internalIterAdapter) SeekLT(key []byte, flags base.SeekLTFlags) bool { 44 return i.update(i.internalIterator.SeekLT(key, flags)) 45 } 46 47 func (i *internalIterAdapter) First() bool { 48 return i.update(i.internalIterator.First()) 49 } 50 51 func (i *internalIterAdapter) Last() bool { 52 return i.update(i.internalIterator.Last()) 53 } 54 55 func (i *internalIterAdapter) Next() bool { 56 return i.update(i.internalIterator.Next()) 57 } 58 59 func (i *internalIterAdapter) Prev() bool { 60 return i.update(i.internalIterator.Prev()) 61 } 62 63 func (i *internalIterAdapter) Key() *InternalKey { 64 return i.key 65 } 66 67 func (i *internalIterAdapter) Value() []byte { 68 return i.val 69 } 70 71 func (i *internalIterAdapter) Valid() bool { 72 return i.key != nil 73 }