native_comparator_wrapper_test.cc 1.4 KB

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