Add more iterator functions

This commit is contained in:
Ankit Gupta 2014-04-19 03:35:01 -07:00
parent 5bbeefaa49
commit eda398491a
3 changed files with 45 additions and 0 deletions

View File

@ -145,6 +145,9 @@ public class RocksDBSample {
Iterator iterator = db.iterator();
iterator.seekToFirst();
assert(iterator.isValid());
iterator.next();
iterator.seekToLast();
iterator.prev();
iterator.close();
} catch (RocksDBException e) {
System.err.println(e);

View File

@ -22,6 +22,21 @@ public class Iterator {
seekToFirst0(nativeHandle_);
}
public void seekToLast() {
assert(isInitialized());
seekToLast0(nativeHandle_);
}
public void next() {
assert(isInitialized());
next0(nativeHandle_);
}
public void prev() {
assert(isInitialized());
prev0(nativeHandle_);
}
public synchronized void close() {
if(nativeHandle_ != 0) {
close0(nativeHandle_);
@ -39,4 +54,7 @@ public class Iterator {
private native boolean isValid0(long handle);
private native void close0(long handle);
private native void seekToFirst0(long handle);
private native void seekToLast0(long handle);
private native void next0(long handle);
private native void prev0(long handle);
}

View File

@ -30,6 +30,30 @@ void Java_org_rocksdb_Iterator_seekToFirst0(
st->SeekToFirst();
}
void Java_org_rocksdb_Iterator_seekToLast0(
JNIEnv* env, jobject jobj, jlong handle) {
auto st = reinterpret_cast<rocksdb::Iterator*>(handle);
assert(st != nullptr);
st->SeekToLast();
}
void Java_org_rocksdb_Iterator_next0(
JNIEnv* env, jobject jobj, jlong handle) {
auto st = reinterpret_cast<rocksdb::Iterator*>(handle);
assert(st != nullptr);
st->Next();
}
void Java_org_rocksdb_Iterator_prev0(
JNIEnv* env, jobject jobj, jlong handle) {
auto st = reinterpret_cast<rocksdb::Iterator*>(handle);
assert(st != nullptr);
st->Prev();
}
void Java_org_rocksdb_Iterator_close0(
JNIEnv* env, jobject jobj, jlong handle) {
auto st = reinterpret_cast<rocksdb::Iterator*>(handle);