set_comparator.h 829 B

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