hash_index_reader.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
  2. // This source code is licensed under both the GPLv2 (found in the
  3. // COPYING file in the root directory) and Apache 2.0 License
  4. // (found in the LICENSE.Apache file in the root directory).
  5. //
  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.
  9. #pragma once
  10. #include "table/block_based/index_reader_common.h"
  11. namespace ROCKSDB_NAMESPACE {
  12. // Index that leverages an internal hash table to quicken the lookup for a given
  13. // key.
  14. class HashIndexReader : public BlockBasedTable::IndexReaderCommon {
  15. public:
  16. static Status Create(const BlockBasedTable* table, const ReadOptions& ro,
  17. FilePrefetchBuffer* prefetch_buffer,
  18. InternalIterator* meta_index_iter, bool use_cache,
  19. bool prefetch, bool pin,
  20. BlockCacheLookupContext* lookup_context,
  21. std::unique_ptr<IndexReader>* index_reader);
  22. InternalIteratorBase<IndexValue>* NewIterator(
  23. const ReadOptions& read_options, bool disable_prefix_seek,
  24. IndexBlockIter* iter, GetContext* get_context,
  25. BlockCacheLookupContext* lookup_context) override;
  26. size_t ApproximateMemoryUsage() const override {
  27. size_t usage = ApproximateIndexBlockMemoryUsage();
  28. #ifdef ROCKSDB_MALLOC_USABLE_SIZE
  29. usage += malloc_usable_size(const_cast<HashIndexReader*>(this));
  30. #else
  31. if (prefix_index_) {
  32. usage += prefix_index_->ApproximateMemoryUsage();
  33. }
  34. usage += sizeof(*this);
  35. #endif // ROCKSDB_MALLOC_USABLE_SIZE
  36. return usage;
  37. }
  38. private:
  39. HashIndexReader(const BlockBasedTable* t, CachableEntry<Block>&& index_block)
  40. : IndexReaderCommon(t, std::move(index_block)) {}
  41. std::unique_ptr<BlockPrefixIndex> prefix_index_;
  42. };
  43. } // namespace ROCKSDB_NAMESPACE