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_DB_MEMTABLE_H_6#define STORAGE_LEVELDB_DB_MEMTABLE_H_8#include <string>10#include "db/dbformat.h"11#include "db/skiplist.h"12#include "leveldb/db.h"13#include "util/arena.h"15namespace leveldb {17class InternalKeyComparator;18class MemTableIterator;20class MemTable {21public:22// MemTables are reference counted. The initial reference count23// is zero and the caller must call Ref() at least once.24explicit MemTable(const InternalKeyComparator& comparator);26MemTable(const MemTable&) = delete;27MemTable& operator=(const MemTable&) = delete;29// Increase reference count.30void Ref() { ++refs_; }32// Drop reference count. Delete if no more references exist.33void Unref() {34--refs_;35assert(refs_ >= 0);36if (refs_ <= 0) {37delete this;38}39}41// Returns an estimate of the number of bytes of data in use by this42// data structure. It is safe to call when MemTable is being modified.43size_t ApproximateMemoryUsage();45// Return an iterator that yields the contents of the memtable.46//47// The caller must ensure that the underlying MemTable remains live48// while the returned iterator is live. The keys returned by this49// iterator are internal keys encoded by AppendInternalKey in the50// db/format.{h,cc} module.51Iterator* NewIterator();53// Add an entry into memtable that maps key to value at the54// specified sequence number and with the specified type.55// Typically value will be empty if type==kTypeDeletion.56void Add(SequenceNumber seq, ValueType type, const Slice& key,57const Slice& value);59// If memtable contains a value for key, store it in *value and return true.60// If memtable contains a deletion for key, store a NotFound() error61// in *status and return true.62// Else, return false.63bool Get(const LookupKey& key, std::string* value, Status* s);65private:66friend class MemTableIterator;67friend class MemTableBackwardIterator;69struct KeyComparator {70const InternalKeyComparator comparator;71explicit KeyComparator(const InternalKeyComparator& c) : comparator(c) {}72int operator()(const char* a, const char* b) const;73};75typedef SkipList<const char*, KeyComparator> Table;77~MemTable(); // Private since only Unref() should be used to delete it79KeyComparator comparator_;80int refs_;81Arena arena_;82Table table_;83};85} // namespace leveldb87#endif // STORAGE_LEVELDB_DB_MEMTABLE_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.