set_comparator.h 862 B

123456789101112131415161718192021222324
  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. #pragma once
  6. #include "rocksdb/comparator.h"
  7. namespace ROCKSDB_NAMESPACE {
  8. // A comparator to be used in std::set
  9. struct SetComparator {
  10. explicit SetComparator() : user_comparator_(BytewiseComparator()) {}
  11. explicit SetComparator(const Comparator* user_comparator)
  12. : user_comparator_(user_comparator ? user_comparator
  13. : BytewiseComparator()) {}
  14. bool operator()(const Slice& lhs, const Slice& rhs) const {
  15. return user_comparator_->Compare(lhs, rhs) < 0;
  16. }
  17. private:
  18. const Comparator* user_comparator_;
  19. };
  20. } // namespace ROCKSDB_NAMESPACE