Skip to content

Commit

Permalink
Add more iterator functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Ankit Gupta committed Apr 19, 2014
1 parent 5bbeefa commit eda3984
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
3 changes: 3 additions & 0 deletions java/RocksDBSample.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ public static void main(String[] args) {
Iterator iterator = db.iterator();
iterator.seekToFirst();
assert(iterator.isValid());
iterator.next();
iterator.seekToLast();
iterator.prev();
iterator.close();
} catch (RocksDBException e) {
System.err.println(e);
Expand Down
18 changes: 18 additions & 0 deletions java/org/rocksdb/Iterator.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,21 @@ public void seekToFirst() {
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_);
Expand All @@ -39,4 +54,7 @@ private boolean isInitialized() {
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);
}
24 changes: 24 additions & 0 deletions java/rocksjni/iterator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit eda3984

Please sign in to comment.