Class Iterator
- Namespace
- RocksDbNet
- Assembly
- RocksDb.Net.dll
Iterates over the key-value pairs in a RocksDb database
or a single column family. Implements forward and reverse iteration.
Maps to rocksdb_iterator_t.
public sealed class Iterator : RocksDbHandle, IDisposable
- Inheritance
-
Iterator
- Implements
- Inherited Members
Methods
AsEnumerable()
Enumerates all key-value pairs forward from the current position, returning heap-allocated copies. Use Key() / Value() directly for zero-copy access within a manual loop.
public IEnumerable<(byte[] Key, byte[] Value)> AsEnumerable()
Returns
- IEnumerable<(byte[] Key, byte[] Value)>
CheckForError()
Throws a RocksDbException if the iterator is in an error state.
public void CheckForError()
DisposeHandle()
Releases the native handle. Called during disposal.
protected override void DisposeHandle()
Remarks
Protected rather than public: it destroys the native object without marking this instance disposed or clearing the handle, so calling it from outside and then disposing normally would free the same pointer twice. It was the most Dispose-looking member on the type. Callers want Dispose().
ForEach(ForEachDelegate)
Invokes the specified delegate for each key/value pair in the collection, in enumeration order.
public void ForEach(Iterator.ForEachDelegate action)
Parameters
actionIterator.ForEachDelegateThe delegate to invoke for each key/value pair. The delegate receives the current key and value as arguments. Cannot be null.
Remarks
If the collection is modified during enumeration, the behavior of this method is undefined. Any exception thrown by the delegate will halt enumeration and propagate to the caller.
GetEnumerator()
Returns an enumerator that iterates through the collection.
public Iterator.Enumerator GetEnumerator()
Returns
- Iterator.Enumerator
An enumerator that can be used to iterate through the collection.
IsValid()
Returns true if the iterator is positioned at a valid entry.
public bool IsValid()
Returns
Key()
Returns the current key as a read-only span. The span is valid only until the next iterator operation.
public ReadOnlySpan<byte> Key()
Returns
KeyAsString()
Returns the current key decoded as a UTF-8 string.
public string KeyAsString()
Returns
KeyToArray()
Returns a copy of the current key as a byte array.
public byte[] KeyToArray()
Returns
- byte[]
Next()
Moves to the next entry. Call IsValid() before reading key/value.
public void Next()
Prev()
Moves to the previous entry. Call IsValid() before reading key/value.
public void Prev()
Refresh()
Refreshes the iterator using the current state of the DB. Only valid for iterators that support refresh (e.g. non-tailing iterators).
public void Refresh()
Seek(ReadOnlySpan<byte>)
Positions the iterator at the first key that is >= key.
public void Seek(ReadOnlySpan<byte> key)
Parameters
keyReadOnlySpan<byte>
Seek(string)
Seeks using a UTF-8 encoded string key.
public void Seek(string key)
Parameters
keystring
SeekForPrev(ReadOnlySpan<byte>)
Positions the iterator at the last key that is <= key.
public void SeekForPrev(ReadOnlySpan<byte> key)
Parameters
keyReadOnlySpan<byte>
SeekForPrev(string)
Seeks using a UTF-8 encoded string key (SeekForPrev direction).
public void SeekForPrev(string key)
Parameters
keystring
SeekToFirst()
Positions the iterator at the first key in the database.
public void SeekToFirst()
SeekToLast()
Positions the iterator at the last key in the database.
public void SeekToLast()
Value()
Returns the current value as a read-only span. The span is valid only until the next iterator operation.
public ReadOnlySpan<byte> Value()
Returns
ValueAsString()
Returns the current value decoded as a UTF-8 string.
public string ValueAsString()
Returns
ValueToArray()
Returns a copy of the current value as a byte array.
public byte[] ValueToArray()
Returns
- byte[]