From 110abc5bba8c807f32a3fa5c7ad4e27d086aa805 Mon Sep 17 00:00:00 2001 From: nan01ab Date: Tue, 7 Jan 2025 10:10:30 +0800 Subject: [PATCH] Fix: keep the first parameter name of the Seek method the same (#3652) Co-authored-by: Shargon --- src/Neo/Persistence/IReadOnlyStore.cs | 4 ++-- src/Neo/Persistence/MemorySnapshot.cs | 1 + src/Neo/Persistence/MemoryStore.cs | 1 + src/Plugins/LevelDBStore/IO/Data/LevelDB/Helper.cs | 9 ++++----- src/Plugins/LevelDBStore/Plugins/Storage/Snapshot.cs | 5 +++-- src/Plugins/LevelDBStore/Plugins/Storage/Store.cs | 5 +++-- src/Plugins/RocksDBStore/Plugins/Storage/Snapshot.cs | 1 + src/Plugins/RocksDBStore/Plugins/Storage/Store.cs | 1 + 8 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/Neo/Persistence/IReadOnlyStore.cs b/src/Neo/Persistence/IReadOnlyStore.cs index 163a1f21ec..f7ee901fa9 100644 --- a/src/Neo/Persistence/IReadOnlyStore.cs +++ b/src/Neo/Persistence/IReadOnlyStore.cs @@ -22,10 +22,10 @@ public interface IReadOnlyStore /// /// Seeks to the entry with the specified key. /// - /// The key to be sought. + /// The key(i.e. start key) or prefix to be sought. /// The direction of seek. /// An enumerator containing all the entries after seeking. - IEnumerable<(byte[] Key, byte[] Value)> Seek(byte[] key, SeekDirection direction); + IEnumerable<(byte[] Key, byte[] Value)> Seek(byte[] keyOrPrefix, SeekDirection direction); /// /// Reads a specified entry from the database. diff --git a/src/Neo/Persistence/MemorySnapshot.cs b/src/Neo/Persistence/MemorySnapshot.cs index 4817cc963e..ca772d9127 100644 --- a/src/Neo/Persistence/MemorySnapshot.cs +++ b/src/Neo/Persistence/MemorySnapshot.cs @@ -54,6 +54,7 @@ public void Put(byte[] key, byte[] value) writeBatch[key[..]] = value[..]; } + /// public IEnumerable<(byte[] Key, byte[] Value)> Seek(byte[] keyOrPrefix, SeekDirection direction = SeekDirection.Forward) { ByteArrayComparer comparer = direction == SeekDirection.Forward ? ByteArrayComparer.Default : ByteArrayComparer.Reverse; diff --git a/src/Neo/Persistence/MemoryStore.cs b/src/Neo/Persistence/MemoryStore.cs index 3107ebdddd..cb57210c7d 100644 --- a/src/Neo/Persistence/MemoryStore.cs +++ b/src/Neo/Persistence/MemoryStore.cs @@ -47,6 +47,7 @@ public void Put(byte[] key, byte[] value) _innerData[key[..]] = value[..]; } + /// public IEnumerable<(byte[] Key, byte[] Value)> Seek(byte[] keyOrPrefix, SeekDirection direction = SeekDirection.Forward) { if (direction == SeekDirection.Backward && keyOrPrefix?.Length == 0) yield break; diff --git a/src/Plugins/LevelDBStore/IO/Data/LevelDB/Helper.cs b/src/Plugins/LevelDBStore/IO/Data/LevelDB/Helper.cs index c224d23c6d..b689a17681 100644 --- a/src/Plugins/LevelDBStore/IO/Data/LevelDB/Helper.cs +++ b/src/Plugins/LevelDBStore/IO/Data/LevelDB/Helper.cs @@ -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()) diff --git a/src/Plugins/LevelDBStore/Plugins/Storage/Snapshot.cs b/src/Plugins/LevelDBStore/Plugins/Storage/Snapshot.cs index d9f6772a0b..9b8364604f 100644 --- a/src/Plugins/LevelDBStore/Plugins/Storage/Snapshot.cs +++ b/src/Plugins/LevelDBStore/Plugins/Storage/Snapshot.cs @@ -54,9 +54,10 @@ public void Dispose() _readOptions.Dispose(); } - public IEnumerable<(byte[] Key, byte[] Value)> Seek(byte[] prefix, SeekDirection direction = SeekDirection.Forward) + /// + 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) diff --git a/src/Plugins/LevelDBStore/Plugins/Storage/Store.cs b/src/Plugins/LevelDBStore/Plugins/Storage/Store.cs index 0a0f630613..622b98e858 100644 --- a/src/Plugins/LevelDBStore/Plugins/Storage/Store.cs +++ b/src/Plugins/LevelDBStore/Plugins/Storage/Store.cs @@ -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); + /// + public IEnumerable<(byte[], byte[])> Seek(byte[] keyOrPrefix, SeekDirection direction = SeekDirection.Forward) => + _db.Seek(ReadOptions.Default, keyOrPrefix, direction); public IEnumerator> GetEnumerator() => _db.GetEnumerator(); diff --git a/src/Plugins/RocksDBStore/Plugins/Storage/Snapshot.cs b/src/Plugins/RocksDBStore/Plugins/Storage/Snapshot.cs index 4da29e41fe..64d962afaa 100644 --- a/src/Plugins/RocksDBStore/Plugins/Storage/Snapshot.cs +++ b/src/Plugins/RocksDBStore/Plugins/Storage/Snapshot.cs @@ -49,6 +49,7 @@ public void Put(byte[] key, byte[] value) batch.Put(key, value); } + /// public IEnumerable<(byte[] Key, byte[] Value)> Seek(byte[] keyOrPrefix, SeekDirection direction) { if (keyOrPrefix == null) keyOrPrefix = Array.Empty(); diff --git a/src/Plugins/RocksDBStore/Plugins/Storage/Store.cs b/src/Plugins/RocksDBStore/Plugins/Storage/Store.cs index 3f8121ca07..68acf002af 100644 --- a/src/Plugins/RocksDBStore/Plugins/Storage/Store.cs +++ b/src/Plugins/RocksDBStore/Plugins/Storage/Store.cs @@ -36,6 +36,7 @@ public ISnapshot GetSnapshot() return new Snapshot(db); } + /// public IEnumerable<(byte[] Key, byte[] Value)> Seek(byte[] keyOrPrefix, SeekDirection direction = SeekDirection.Forward) { if (keyOrPrefix == null) keyOrPrefix = Array.Empty();