作者: 谢瑞阳 10225101483 徐翔宇 10225101535
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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