作者: 韩晨旭 10225101440 李畅 10225102463
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 regels
2.1 KiB

  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 be
  3. // found in the LICENSE file. See the AUTHORS file for names of contributors.
  4. #ifndef STORAGE_LEVELDB_INCLUDE_COMPARATOR_H_
  5. #define STORAGE_LEVELDB_INCLUDE_COMPARATOR_H_
  6. #include <string>
  7. namespace leveldb {
  8. class Slice;
  9. // A Comparator object provides a total order across slices that are
  10. // used as keys in an sstable or a database.
  11. class Comparator {
  12. public:
  13. virtual ~Comparator();
  14. // Three-way comparison. Returns value:
  15. // < 0 iff "a" < "b",
  16. // == 0 iff "a" == "b",
  17. // > 0 iff "a" > "b"
  18. virtual int Compare(const Slice& a, const Slice& b) const = 0;
  19. // The name of the comparator. Used to check for comparator
  20. // mismatches (i.e., a DB created with one comparator is
  21. // accessed using a different comparator.
  22. //
  23. // The client of this package should switch to a new name whenever
  24. // the comparator implementation changes in a way that will cause
  25. // the relative ordering of any two keys to change.
  26. //
  27. // Names starting with "leveldb." are reserved and should not be used
  28. // by any clients of this package.
  29. virtual const char* Name() const = 0;
  30. // Advanced functions: these are used to reduce the space requirements
  31. // for internal data structures like index blocks.
  32. // If *start < limit, changes *start to a short string in [start,limit).
  33. // Simple comparator implementations may return with *start unchanged,
  34. // i.e., an implementation of this method that does nothing is correct.
  35. virtual void FindShortestSeparator(
  36. std::string* start,
  37. const Slice& limit) const = 0;
  38. // Changes *key to a short string >= *key.
  39. // Simple comparator implementations may return with *key unchanged,
  40. // i.e., an implementation of this method that does nothing is correct.
  41. virtual void FindShortSuccessor(std::string* key) const = 0;
  42. };
  43. // Return a builtin comparator that uses lexicographic byte-wise
  44. // ordering. The result remains the property of this module and
  45. // must not be deleted.
  46. extern const Comparator* BytewiseComparator();
  47. }
  48. #endif // STORAGE_LEVELDB_INCLUDE_COMPARATOR_H_