Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2011 The LevelDB Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file. See the AUTHORS file for names of contributors.5#ifndef STORAGE_LEVELDB_TABLE_ITERATOR_WRAPPER_H_6#define STORAGE_LEVELDB_TABLE_ITERATOR_WRAPPER_H_8#include "leveldb/iterator.h"9#include "leveldb/slice.h"11namespace leveldb {13// A internal wrapper class with an interface similar to Iterator that14// caches the valid() and key() results for an underlying iterator.15// This can help avoid virtual function calls and also gives better16// cache locality.17class IteratorWrapper {18public:19IteratorWrapper() : iter_(nullptr), valid_(false) {}20explicit IteratorWrapper(Iterator* iter) : iter_(nullptr) { Set(iter); }21~IteratorWrapper() { delete iter_; }22Iterator* iter() const { return iter_; }24// Takes ownership of "iter" and will delete it when destroyed, or25// when Set() is invoked again.26void Set(Iterator* iter) {27delete iter_;28iter_ = iter;29if (iter_ == nullptr) {30valid_ = false;31} else {32Update();33}34}36// Iterator interface methods37bool Valid() const { return valid_; }38Slice key() const {39assert(Valid());40return key_;41}42Slice value() const {43assert(Valid());44return iter_->value();45}46// Methods below require iter() != nullptr47Status status() const {48assert(iter_);49return iter_->status();50}51void Next() {52assert(iter_);53iter_->Next();54Update();55}56void Prev() {57assert(iter_);58iter_->Prev();59Update();60}61void Seek(const Slice& k) {62assert(iter_);63iter_->Seek(k);64Update();65}66void SeekToFirst() {67assert(iter_);68iter_->SeekToFirst();69Update();70}71void SeekToLast() {72assert(iter_);73iter_->SeekToLast();74Update();75}77private:78void Update() {79valid_ = iter_->Valid();80if (valid_) {81key_ = iter_->key();82}83}85Iterator* iter_;86bool valid_;87Slice key_;88};90} // namespace leveldb92#endif // STORAGE_LEVELDB_TABLE_ITERATOR_WRAPPER_H_
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.