public class RocksIterator extends RocksObject
An iterator yields a sequence of key/value pairs from a source. The following class defines the interface. Multiple implementations are provided by this library. In particular, iterators are provided to access the contents of a Table or a DB.
Multiple threads can invoke const methods on an RocksIterator without external synchronization, but if any of the threads may call a non-const method, all threads accessing the same RocksIterator must use external synchronization.
RocksObject
nativeHandle_
Constructor and Description |
---|
RocksIterator(RocksDB rocksDB,
long nativeHandle) |
Modifier and Type | Method and Description |
---|---|
protected void |
disposeInternal()
Deletes underlying C++ iterator pointer.
|
boolean |
isValid()
An iterator is either positioned at a key/value pair, or
not valid.
|
byte[] |
key()
Return the key for the current entry.
|
void |
next()
Moves to the next entry in the source.
|
void |
prev()
Moves to the previous entry in the source.
|
void |
seek(byte[] target)
Position at the first key in the source that at or past target
The iterator is valid after this call iff the source contains
an entry that comes at or past target.
|
void |
seekToFirst()
Position at the first key in the source.
|
void |
seekToLast()
Position at the last key in the source.
|
void |
status()
If an error has occurred, return it.
|
byte[] |
value()
Return the value for the current entry.
|
disOwnNativeHandle, dispose, finalize, isInitialized, isOwningNativeHandle
public RocksIterator(RocksDB rocksDB, long nativeHandle)
public boolean isValid()
public void seekToFirst()
public void seekToLast()
public void next()
Moves to the next entry in the source. After this call, Valid() is true iff the iterator was not positioned at the last entry in the source.
REQUIRES: isValid()
public void prev()
Moves to the previous entry in the source. After this call, Valid() is true iff the iterator was not positioned at the first entry in source.
REQUIRES: isValid()
public byte[] key()
Return the key for the current entry. The underlying storage for the returned slice is valid only until the next modification of the iterator.
REQUIRES: isValid()
public byte[] value()
Return the value for the current entry. The underlying storage for the returned slice is valid only until the next modification of the iterator.
REQUIRES: !AtEnd() && !AtStart()
public void seek(byte[] target)
Position at the first key in the source that at or past target The iterator is valid after this call iff the source contains an entry that comes at or past target.
target
- byte array describing a key or a
key prefix to seek for.public void status() throws RocksDBException
RocksDBException
- thrown if error happens in underlying
native library.protected void disposeInternal()
Deletes underlying C++ iterator pointer.
Note: the underlying handle can only be safely deleted if the RocksDB
instance related to a certain RocksIterator is still valid and initialized.
Therefore disposeInternal()
checks if the RocksDB is initialized
before freeing the native handle.
disposeInternal
in class RocksObject