Skip to content

Commit

Permalink
Fix: keep the first parameter name of the Seek method the same (neo-p…
Browse files Browse the repository at this point in the history
…roject#3652)

Co-authored-by: Shargon <[email protected]>
  • Loading branch information
nan01ab and shargon authored Jan 7, 2025
1 parent 8c3938d commit 110abc5
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/Neo/Persistence/IReadOnlyStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ public interface IReadOnlyStore
/// <summary>
/// Seeks to the entry with the specified key.
/// </summary>
/// <param name="key">The key to be sought.</param>
/// <param name="keyOrPrefix">The key(i.e. start key) or prefix to be sought.</param>
/// <param name="direction">The direction of seek.</param>
/// <returns>An enumerator containing all the entries after seeking.</returns>
IEnumerable<(byte[] Key, byte[] Value)> Seek(byte[] key, SeekDirection direction);
IEnumerable<(byte[] Key, byte[] Value)> Seek(byte[] keyOrPrefix, SeekDirection direction);

/// <summary>
/// Reads a specified entry from the database.
Expand Down
1 change: 1 addition & 0 deletions src/Neo/Persistence/MemorySnapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public void Put(byte[] key, byte[] value)
writeBatch[key[..]] = value[..];
}

/// <inheritdoc/>
public IEnumerable<(byte[] Key, byte[] Value)> Seek(byte[] keyOrPrefix, SeekDirection direction = SeekDirection.Forward)
{
ByteArrayComparer comparer = direction == SeekDirection.Forward ? ByteArrayComparer.Default : ByteArrayComparer.Reverse;
Expand Down
1 change: 1 addition & 0 deletions src/Neo/Persistence/MemoryStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public void Put(byte[] key, byte[] value)
_innerData[key[..]] = value[..];
}

/// <inheritdoc/>
public IEnumerable<(byte[] Key, byte[] Value)> Seek(byte[] keyOrPrefix, SeekDirection direction = SeekDirection.Forward)
{
if (direction == SeekDirection.Backward && keyOrPrefix?.Length == 0) yield break;
Expand Down
9 changes: 4 additions & 5 deletions src/Plugins/LevelDBStore/IO/Data/LevelDB/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,21 @@ namespace Neo.IO.Storage.LevelDB
{
public static class Helper
{
public static IEnumerable<(byte[], byte[])> Seek(this DB db, ReadOptions options, byte[] prefix, SeekDirection direction)
public static IEnumerable<(byte[], byte[])> Seek(this DB db, ReadOptions options, byte[] keyOrPrefix, SeekDirection direction)
{
using Iterator it = db.CreateIterator(options);
if (direction == SeekDirection.Forward)
{
for (it.Seek(prefix); it.Valid(); it.Next())
for (it.Seek(keyOrPrefix); it.Valid(); it.Next())
yield return new(it.Key(), it.Value());
}
else
{
// SeekForPrev

it.Seek(prefix);
it.Seek(keyOrPrefix);
if (!it.Valid())
it.SeekToLast();
else if (it.Key().AsSpan().SequenceCompareTo(prefix) > 0)
else if (it.Key().AsSpan().SequenceCompareTo(keyOrPrefix) > 0)
it.Prev();

for (; it.Valid(); it.Prev())
Expand Down
5 changes: 3 additions & 2 deletions src/Plugins/LevelDBStore/Plugins/Storage/Snapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ public void Dispose()
_readOptions.Dispose();
}

public IEnumerable<(byte[] Key, byte[] Value)> Seek(byte[] prefix, SeekDirection direction = SeekDirection.Forward)
/// <inheritdoc/>
public IEnumerable<(byte[] Key, byte[] Value)> Seek(byte[] keyOrPrefix, SeekDirection direction = SeekDirection.Forward)
{
return _db.Seek(_readOptions, prefix, direction);
return _db.Seek(_readOptions, keyOrPrefix, direction);
}

public void Put(byte[] key, byte[] value)
Expand Down
5 changes: 3 additions & 2 deletions src/Plugins/LevelDBStore/Plugins/Storage/Store.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ public bool TryGet(byte[] key, out byte[] value)
return value != null;
}

public IEnumerable<(byte[], byte[])> Seek(byte[] prefix, SeekDirection direction = SeekDirection.Forward) =>
_db.Seek(ReadOptions.Default, prefix, direction);
/// <inheritdoc/>
public IEnumerable<(byte[], byte[])> Seek(byte[] keyOrPrefix, SeekDirection direction = SeekDirection.Forward) =>
_db.Seek(ReadOptions.Default, keyOrPrefix, direction);

public IEnumerator<KeyValuePair<byte[], byte[]>> GetEnumerator() =>
_db.GetEnumerator();
Expand Down
1 change: 1 addition & 0 deletions src/Plugins/RocksDBStore/Plugins/Storage/Snapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public void Put(byte[] key, byte[] value)
batch.Put(key, value);
}

/// <inheritdoc/>
public IEnumerable<(byte[] Key, byte[] Value)> Seek(byte[] keyOrPrefix, SeekDirection direction)
{
if (keyOrPrefix == null) keyOrPrefix = Array.Empty<byte>();
Expand Down
1 change: 1 addition & 0 deletions src/Plugins/RocksDBStore/Plugins/Storage/Store.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public ISnapshot GetSnapshot()
return new Snapshot(db);
}

/// <inheritdoc/>
public IEnumerable<(byte[] Key, byte[] Value)> Seek(byte[] keyOrPrefix, SeekDirection direction = SeekDirection.Forward)
{
if (keyOrPrefix == null) keyOrPrefix = Array.Empty<byte>();
Expand Down

0 comments on commit 110abc5

Please sign in to comment.