]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/table/iterator_wrapper.h
1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under the BSD-style license found in the
3 // LICENSE file in the root directory of this source tree. An additional grant
4 // of patent rights can be found in the PATENTS file in the same directory.
6 // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
7 // Use of this source code is governed by a BSD-style license that can be
8 // found in the LICENSE file. See the AUTHORS file for names of contributors.
14 #include "table/internal_iterator.h"
18 // A internal wrapper class with an interface similar to Iterator that caches
19 // the valid() and key() results for an underlying iterator.
20 // This can help avoid virtual function calls and also gives better
22 class IteratorWrapper
{
24 IteratorWrapper() : iter_(nullptr), valid_(false) {}
25 explicit IteratorWrapper(InternalIterator
* _iter
) : iter_(nullptr) {
29 InternalIterator
* iter() const { return iter_
; }
31 // Set the underlying Iterator to _iter and return
32 // previous underlying Iterator.
33 InternalIterator
* Set(InternalIterator
* _iter
) {
34 InternalIterator
* old_iter
= iter_
;
37 if (iter_
== nullptr) {
45 void DeleteIter(bool is_arena_mode
) {
50 iter_
->~InternalIterator();
55 // Iterator interface methods
56 bool Valid() const { return valid_
; }
57 Slice
key() const { assert(Valid()); return key_
; }
58 Slice
value() const { assert(Valid()); return iter_
->value(); }
59 // Methods below require iter() != nullptr
60 Status
status() const { assert(iter_
); return iter_
->status(); }
61 void Next() { assert(iter_
); iter_
->Next(); Update(); }
62 void Prev() { assert(iter_
); iter_
->Prev(); Update(); }
63 void Seek(const Slice
& k
) { assert(iter_
); iter_
->Seek(k
); Update(); }
64 void SeekForPrev(const Slice
& k
) {
66 iter_
->SeekForPrev(k
);
69 void SeekToFirst() { assert(iter_
); iter_
->SeekToFirst(); Update(); }
70 void SeekToLast() { assert(iter_
); iter_
->SeekToLast(); Update(); }
72 void SetPinnedItersMgr(PinnedIteratorsManager
* pinned_iters_mgr
) {
74 iter_
->SetPinnedItersMgr(pinned_iters_mgr
);
76 bool IsKeyPinned() const {
78 return iter_
->IsKeyPinned();
80 bool IsValuePinned() const {
82 return iter_
->IsValuePinned();
87 valid_
= iter_
->Valid();
93 InternalIterator
* iter_
;
99 // Return an empty iterator (yields nothing) allocated from arena.
100 extern InternalIterator
* NewEmptyInternalIterator(Arena
* arena
);
102 // Return an empty iterator with the specified status, allocated arena.
103 extern InternalIterator
* NewErrorInternalIterator(const Status
& status
,
106 } // namespace rocksdb