native_comparator_wrapper_test.cc 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. #include <jni.h>
  6. #include <string>
  7. #include "include/org_rocksdb_NativeComparatorWrapperTest_NativeStringComparatorWrapper.h"
  8. #include "rocksdb/comparator.h"
  9. #include "rocksdb/slice.h"
  10. #include "rocksjni/cplusplus_to_java_convert.h"
  11. namespace ROCKSDB_NAMESPACE {
  12. class NativeComparatorWrapperTestStringComparator : public Comparator {
  13. const char* Name() const {
  14. return "NativeComparatorWrapperTestStringComparator";
  15. }
  16. int Compare(const Slice& a, const Slice& b) const {
  17. return a.ToString().compare(b.ToString());
  18. }
  19. void FindShortestSeparator(std::string* /*start*/,
  20. const Slice& /*limit*/) const {
  21. return;
  22. }
  23. void FindShortSuccessor(std::string* /*key*/) const { return; }
  24. };
  25. } // namespace ROCKSDB_NAMESPACE
  26. /*
  27. * Class: org_rocksdb_NativeComparatorWrapperTest_NativeStringComparatorWrapper
  28. * Method: newStringComparator
  29. * Signature: ()J
  30. */
  31. jlong Java_org_rocksdb_NativeComparatorWrapperTest_00024NativeStringComparatorWrapper_newStringComparator(
  32. JNIEnv* /*env*/, jobject /*jobj*/) {
  33. auto* comparator =
  34. new ROCKSDB_NAMESPACE::NativeComparatorWrapperTestStringComparator();
  35. return GET_CPLUSPLUS_POINTER(comparator);
  36. }