text: 
  //此源码被清华学神尹成大魔王专业翻译分析并修改
  //尹成QQ77025077
  //尹成微信18510341407
  //尹成所在QQ群721929980
  //尹成邮箱 yinc13@mails.tsinghua.edu.cn
  //尹成毕业于清华大学,微软区块链领域全球最有价值专家
  //https://mvp.microsoft.com/zh-cn/PublicProfile/4033620
  //版权所有（c）2011至今，Facebook，Inc.保留所有权利。
  //此源代码在两个gplv2下都获得了许可（在
  //复制根目录中的文件）和Apache2.0许可证
  //（在根目录的license.apache文件中找到）。
  //
  //版权所有（c）2011 LevelDB作者。版权所有。
  //此源代码的使用受可以
  //在许可证文件中找到。有关参与者的名称，请参阅作者文件。
  
  #pragma once
  
  #include <atomic>
  #include <string>
  
  #include "port/port.h"
  #include "rocksdb/cache.h"
  #include "util/hash.h"
  
  namespace rocksdb {
  
  //单缓存碎片接口。
  class CacheShard {
   public:
    CacheShard() = default;
    virtual ~CacheShard() = default;
  
    virtual Status Insert(const Slice& key, uint32_t hash, void* value,
                          size_t charge,
                          void (*deleter)(const Slice& key, void* value),
                          Cache::Handle** handle, Cache::Priority priority) = 0;
    virtual Cache::Handle* Lookup(const Slice& key, uint32_t hash) = 0;
    virtual bool Ref(Cache::Handle* handle) = 0;
    virtual bool Release(Cache::Handle* handle, bool force_erase = false) = 0;
    virtual void Erase(const Slice& key, uint32_t hash) = 0;
    virtual void SetCapacity(size_t capacity) = 0;
    virtual void SetStrictCapacityLimit(bool strict_capacity_limit) = 0;
    virtual size_t GetUsage() const = 0;
    virtual size_t GetPinnedUsage() const = 0;
    virtual void ApplyToAllCacheEntries(void (*callback)(void*, size_t),
                                        bool thread_safe) = 0;
    virtual void EraseUnRefEntries() = 0;
    virtual std::string GetPrintableOptions() const { return ""; }
  };
  
  //通用缓存接口，它按键散列共享缓存。2^num_shard_位
  //将创建碎片，并将容量平均分配到每个碎片。
  //键由哈希值的最高num_shard_位分割。
  class ShardedCache : public Cache {
   public:
    ShardedCache(size_t capacity, int num_shard_bits, bool strict_capacity_limit);
    virtual ~ShardedCache() = default;
    virtual const char* Name() const override = 0;
    virtual CacheShard* GetShard(int shard) = 0;
    virtual const CacheShard* GetShard(int shard) const = 0;
    virtual void* Value(Handle* handle) override = 0;
    virtual size_t GetCharge(Handle* handle) const = 0;
    virtual uint32_t GetHash(Handle* handle) const = 0;
    virtual void DisownData() override = 0;
  
    virtual void SetCapacity(size_t capacity) override;
    virtual void SetStrictCapacityLimit(bool strict_capacity_limit) override;
  
    virtual Status Insert(const Slice& key, void* value, size_t charge,
                          void (*deleter)(const Slice& key, void* value),
                          Handle** handle, Priority priority) override;
    virtual Handle* Lookup(const Slice& key, Statistics* stats) override;
    virtual bool Ref(Handle* handle) override;
    virtual bool Release(Handle* handle, bool force_erase = false) override;
    virtual void Erase(const Slice& key) override;
    virtual uint64_t NewId() override;
    virtual size_t GetCapacity() const override;
    virtual bool HasStrictCapacityLimit() const override;
    virtual size_t GetUsage() const override;
    virtual size_t GetUsage(Handle* handle) const override;
    virtual size_t GetPinnedUsage() const override;
    virtual void ApplyToAllCacheEntries(void (*callback)(void*, size_t),
                                        bool thread_safe) override;
    virtual void EraseUnRefEntries() override;
    virtual std::string GetPrintableOptions() const override;
  
    int GetNumShardBits() const { return num_shard_bits_; }
  
   private:
    static inline uint32_t HashSlice(const Slice& s) {
      return Hash(s.data(), s.size(), 0);
    }
  
    uint32_t Shard(uint32_t hash) {
  //注意，hash>>32在gcc中生成hash，而不是我们期望的零！
      return (num_shard_bits_ > 0) ? (hash >> (32 - num_shard_bits_)) : 0;
    }
  
    int num_shard_bits_;
    mutable port::Mutex capacity_mutex_;
    size_t capacity_;
    bool strict_capacity_limit_;
    std::atomic<uint64_t> last_id_;
  };
  
  extern int GetDefaultCacheShardBits(size_t capacity);
  
  }  //命名空间rocksdb
  