From eda398491a19ae02ffb304e2686514c171a603c5 Mon Sep 17 00:00:00 2001 From: Ankit Gupta Date: Sat, 19 Apr 2014 03:35:01 -0700 Subject: [PATCH] Add more iterator functions --- java/RocksDBSample.java | 3 +++ java/org/rocksdb/Iterator.java | 18 ++++++++++++++++++ java/rocksjni/iterator.cc | 24 ++++++++++++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/java/RocksDBSample.java b/java/RocksDBSample.java index f4afe79cf..018d86815 100644 --- a/java/RocksDBSample.java +++ b/java/RocksDBSample.java @@ -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); diff --git a/java/org/rocksdb/Iterator.java b/java/org/rocksdb/Iterator.java index 945514230..dbd11015b 100644 --- a/java/org/rocksdb/Iterator.java +++ b/java/org/rocksdb/Iterator.java @@ -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); } \ No newline at end of file diff --git a/java/rocksjni/iterator.cc b/java/rocksjni/iterator.cc index 9f6edd0ee..2f6d0a6b3 100644 --- a/java/rocksjni/iterator.cc +++ b/java/rocksjni/iterator.cc @@ -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(handle); + assert(st != nullptr); + + st->SeekToLast(); +} + +void Java_org_rocksdb_Iterator_next0( + JNIEnv* env, jobject jobj, jlong handle) { + auto st = reinterpret_cast(handle); + assert(st != nullptr); + + st->Next(); +} + +void Java_org_rocksdb_Iterator_prev0( + JNIEnv* env, jobject jobj, jlong handle) { + auto st = reinterpret_cast(handle); + assert(st != nullptr); + + st->Prev(); +} + void Java_org_rocksdb_Iterator_close0( JNIEnv* env, jobject jobj, jlong handle) { auto st = reinterpret_cast(handle);