10225501448 李度 10225101546 陈胤遒 10215501422 高宇菲
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.

64 lines
2.4 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. #include "leveldb/export.h"
  8. namespace leveldb {
  9. class Slice;
  10. // A Comparator object provides a total order across slices that are
  11. // used as keys in an sstable or a database. A Comparator implementation
  12. // must be thread-safe since leveldb may invoke its methods concurrently
  13. // from multiple threads.
  14. class LEVELDB_EXPORT Comparator {
  15. public:
  16. virtual ~Comparator();
  17. // Three-way comparison. Returns value:
  18. // < 0 iff "a" < "b",
  19. // == 0 iff "a" == "b",
  20. // > 0 iff "a" > "b"
  21. virtual int Compare(const Slice& a, const Slice& b) const = 0;
  22. // The name of the comparator. Used to check for comparator
  23. // mismatches (i.e., a DB created with one comparator is
  24. // accessed using a different comparator.
  25. //
  26. // The client of this package should switch to a new name whenever
  27. // the comparator implementation changes in a way that will cause
  28. // the relative ordering of any two keys to change.
  29. //
  30. // Names starting with "leveldb." are reserved and should not be used
  31. // by any clients of this package.
  32. virtual const char* Name() const = 0;
  33. // Advanced functions: these are used to reduce the space requirements
  34. // for internal data structures like index blocks.
  35. // If *start < limit, changes *start to a short string in [start,limit).
  36. // Simple comparator implementations may return with *start unchanged,
  37. // i.e., an implementation of this method that does nothing is correct.
  38. virtual void FindShortestSeparator(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. LEVELDB_EXPORT const Comparator* BytewiseComparator();
  49. } // namespace leveldb
  50. #endif // STORAGE_LEVELDB_INCLUDE_COMPARATOR_H_