Package org.rocksdb
Class NativeComparatorWrapper
- java.lang.Object
-
- org.rocksdb.AbstractNativeReference
-
- org.rocksdb.AbstractImmutableNativeReference
-
- org.rocksdb.RocksCallbackObject
-
- org.rocksdb.AbstractComparator
-
- org.rocksdb.NativeComparatorWrapper
-
- All Implemented Interfaces:
java.lang.AutoCloseable
public abstract class NativeComparatorWrapper extends AbstractComparator
A simple abstraction to allow a Java class to wrap a custom comparator implemented in C++. The native comparator must directly extend rocksdb::Comparator.
-
-
Field Summary
-
Fields inherited from class org.rocksdb.RocksCallbackObject
nativeHandle_
-
Fields inherited from class org.rocksdb.AbstractImmutableNativeReference
owningHandle_
-
-
Constructor Summary
Constructors Constructor Description NativeComparatorWrapper()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompare(java.nio.ByteBuffer s1, java.nio.ByteBuffer s2)Three-way key comparison.protected voiddisposeInternal()We overrideRocksCallbackObject.disposeInternal()as disposing of a native rocksdb::Comparator extension requires a slightly different approach as it is not really a RocksCallbackObjectvoidfindShortestSeparator(java.nio.ByteBuffer start, java.nio.ByteBuffer limit)Used to reduce the space requirements for internal data structures like index blocks.voidfindShortSuccessor(java.nio.ByteBuffer key)Used to reduce the space requirements for internal data structures like index blocks.java.lang.Stringname()The name of the comparator.-
Methods inherited from class org.rocksdb.AbstractComparator
initializeNative, usingDirectBuffers
-
Methods inherited from class org.rocksdb.AbstractImmutableNativeReference
close, disOwnNativeHandle, isOwningHandle
-
Methods inherited from class org.rocksdb.AbstractNativeReference
dispose, finalize
-
-
-
-
Method Detail
-
name
public final java.lang.String name()
Description copied from class:AbstractComparatorThe name of the comparator. Used to check for comparator mismatches (i.e., a DB created with one comparator is accessed using a different comparator). A new name should be used whenever the comparator implementation changes in a way that will cause the relative ordering of any two keys to change. Names starting with "rocksdb." are reserved and should not be used.- Specified by:
namein classAbstractComparator- Returns:
- The name of this comparator implementation
-
compare
public final int compare(java.nio.ByteBuffer s1, java.nio.ByteBuffer s2)Description copied from class:AbstractComparatorThree-way key comparison. Implementations should provide a total order on keys that might be passed to it. The implementation may modify theByteBuffers passed in, though it would be unconventional to modify the "limit" or any of the underlying bytes. As a callback, RocksJava will ensure thatais a different instance fromb.- Specified by:
comparein classAbstractComparator- Parameters:
s1- buffer containing the first key in its "remaining" elementss2- buffer containing the second key in its "remaining" elements- Returns:
- Should return either: 1) < 0 if "a" < "b" 2) == 0 if "a" == "b" 3) > 0 if "a" > "b"
-
findShortestSeparator
public final void findShortestSeparator(java.nio.ByteBuffer start, java.nio.ByteBuffer limit)Description copied from class:AbstractComparatorUsed to reduce the space requirements for internal data structures like index blocks.
If start < limit, you may modify start which is a shorter string in [start, limit).
If you modify start, it is expected that you set the byte buffer so that a subsequent read of start.remaining() bytes from start.position() to start.limit() will obtain the new start value.Simple comparator implementations may return with start unchanged. i.e., an implementation of this method that does nothing is correct.
- Overrides:
findShortestSeparatorin classAbstractComparator- Parameters:
start- the startlimit- the limit
-
findShortSuccessor
public final void findShortSuccessor(java.nio.ByteBuffer key)
Description copied from class:AbstractComparatorUsed to reduce the space requirements for internal data structures like index blocks.
You may change key to a shorter key (key1) where key1 ≥ key.
Simple comparator implementations may return the key unchanged. i.e., an implementation of this method that does nothing is correct.
- Overrides:
findShortSuccessorin classAbstractComparator- Parameters:
key- the key
-
disposeInternal
protected void disposeInternal()
We overrideRocksCallbackObject.disposeInternal()as disposing of a native rocksdb::Comparator extension requires a slightly different approach as it is not really a RocksCallbackObject- Overrides:
disposeInternalin classRocksCallbackObject
-
-