-
Notifications
You must be signed in to change notification settings - Fork 0
Add Set support #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add Set support #46
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds support for ISet<T> collections to the RocksDb.Extensions library, mirroring the existing IList<T> functionality. The implementation refactors the existing list serializers by introducing base classes that can be shared between list and set serializers.
Key Changes:
- Introduced abstract base classes
FixedSizeCollectionSerializerandVariableSizeCollectionSerializerfor code reuse - Created
FixedSizeSetSerializerandVariableSizeSetSerializerfor set-specific implementations - Refactored existing list serializers to inherit from the new base classes
- Updated
RocksDbBuilderto automatically create appropriate serializers forISet<T>types - Added comprehensive test coverage for set support across all serializer types
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| src/RocksDb.Extensions/FixedSizeCollectionSerializer.cs | New abstract base class for serializing collections with fixed-size elements (primitives) |
| src/RocksDb.Extensions/VariableSizeCollectionSerializer.cs | New abstract base class for serializing collections with variable-size elements (strings, complex objects) |
| src/RocksDb.Extensions/FixedSizeSetSerializer.cs | Concrete implementation for serializing ISet with fixed-size elements |
| src/RocksDb.Extensions/VariableSizeSetSerializer.cs | Concrete implementation for serializing ISet with variable-size elements |
| src/RocksDb.Extensions/FixedSizeListSerializer.cs | Refactored to extend FixedSizeCollectionSerializer base class |
| src/RocksDb.Extensions/VariableSizeListSerializer.cs | Refactored to extend VariableSizeCollectionSerializer base class |
| src/RocksDb.Extensions/RocksDbBuilder.cs | Added logic to detect ISet types and create appropriate serializers (fixed vs variable size) |
| test/RocksDb.Extensions.Tests/RocksDbStoreWithProtobufSerializerTests.cs | Added test for set support with Protobuf serializer |
| test/RocksDb.Extensions.Tests/RocksDbStoreWithProtoBufNetSerializerTests.cs | Added test for set support with ProtoBufNet serializer |
| test/RocksDb.Extensions.Tests/RocksDbStoreWithPrimitiveSerializerTests.cs | Added tests for set support with primitive types (int and string) |
| test/RocksDb.Extensions.Tests/RocksDbStoreWithJsonSerializerTests.cs | Added test for set support with JSON serializer |
| README.md | Updated documentation to reflect ISet support alongside IList |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| // Write the elements of the collection | ||
| int offset = sizeof(int); | ||
| var elementSize = (span.Length - offset) / value.Count; |
Copilot
AI
Dec 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Division by zero will occur when value.Count is 0. While TryCalculateSize handles empty collections correctly, WriteTo does not check if the collection is empty before dividing. This will cause a DivideByZeroException when serializing an empty collection. Add a check to return early when value.Count is 0.
|
|
||
| // Read the elements of the collection | ||
| int offset = sizeof(int); | ||
| var elementSize = (buffer.Length - offset) / size; |
Copilot
AI
Dec 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Division by zero will occur when size is 0. The Deserialize method does not check if the deserialized size is 0 before dividing. This will cause a DivideByZeroException when deserializing an empty collection. Add a check to return an empty collection when size is 0.
| [Test] | ||
| public void should_put_and_retrieve_data_with_sets_from_store() | ||
| { | ||
| // Arrange | ||
| using var testFixture = CreateTestFixture<ISet<CacheKey>, ISet<CacheValue>>(); | ||
| var store = testFixture.GetStore<RocksDbGenericStore<ISet<CacheKey>, ISet<CacheValue>>>(); | ||
|
|
||
| // Act | ||
| var cacheKey = Enumerable.Range(0, 100) | ||
| .Select(x => new CacheKey | ||
| { | ||
| Id = x, | ||
| }) | ||
| .ToHashSet(); | ||
|
|
||
| var cacheValue = Enumerable.Range(0, 100) | ||
| .Select(x => new CacheValue | ||
| { | ||
| Id = x, | ||
| Value = $"value-{x}", | ||
| }) | ||
| .ToHashSet(); | ||
|
|
||
| store.Put(cacheKey, cacheValue); | ||
|
|
||
| store.HasKey(cacheKey).ShouldBeTrue(); | ||
| store.TryGet(cacheKey, out var value).ShouldBeTrue(); | ||
| value.ShouldBeEquivalentTo(cacheValue); | ||
| } |
Copilot
AI
Dec 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test suite lacks coverage for empty set scenarios. Add tests that verify storing and retrieving empty sets (both primitive and non-primitive element types) to ensure the serializer handles edge cases correctly.
| [Test] | ||
| public void should_put_and_retrieve_data_with_sets_from_store() | ||
| { | ||
| // Arrange | ||
| using var testFixture = CreateTestFixture<ISet<ProtoNetCacheKey>, ISet<ProtoNetCacheValue>>(); | ||
| var store = testFixture.GetStore<RocksDbGenericStore<ISet<ProtoNetCacheKey>, ISet<ProtoNetCacheValue>>>(); | ||
|
|
||
| // Act | ||
| var cacheKey = Enumerable.Range(0, 100) | ||
| .Select(x => new ProtoNetCacheKey | ||
| { | ||
| Id = x, | ||
| }) | ||
| .ToHashSet(); | ||
|
|
||
| var cacheValue = Enumerable.Range(0, 100) | ||
| .Select(x => new ProtoNetCacheValue | ||
| { | ||
| Id = x, | ||
| Value = $"value-{x}", | ||
| }) | ||
| .ToHashSet(); | ||
|
|
||
| store.Put(cacheKey, cacheValue); | ||
|
|
||
| store.HasKey(cacheKey).ShouldBeTrue(); | ||
| store.TryGet(cacheKey, out var value).ShouldBeTrue(); | ||
| value.ShouldBeEquivalentTo(cacheValue); | ||
| } |
Copilot
AI
Dec 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test suite lacks coverage for empty set scenarios. Add tests that verify storing and retrieving empty sets (both primitive and non-primitive element types) to ensure the serializer handles edge cases correctly.
| [Test] | ||
| public void should_put_and_retrieve_data_from_store_using_set_of_ints() | ||
| { | ||
| // Arrange | ||
| using var testFixture = CreateTestFixture<ISet<int>, ISet<long>>(); | ||
| var store = testFixture.GetStore<RocksDbGenericStore<ISet<int>, ISet<long>>>(); | ||
|
|
||
| // Act | ||
| var key = new HashSet<int> { 1, 2, 3 }; | ||
| var value = new HashSet<long> { 4, 5, 6 }; | ||
| store.Put(key, value); | ||
|
|
||
| // Assert | ||
| store.HasKey(key).ShouldBeTrue(); | ||
| store.TryGet(key, out var cacheValue).ShouldBeTrue(); | ||
| cacheValue.ShouldBeEquivalentTo(value); | ||
| } | ||
|
|
||
| [Test] | ||
| public void should_put_and_retrieve_data_from_store_using_set_of_strings() | ||
| { | ||
| // Arrange | ||
| using var testFixture = CreateTestFixture<ISet<string>, ISet<string>>(); | ||
| var store = testFixture.GetStore<RocksDbGenericStore<ISet<string>, ISet<string>>>(); | ||
| var key = new HashSet<string> { "key1", "key2", string.Empty, "key3" }; | ||
| var value = new HashSet<string> { "value1", string.Empty, "value2", "value3" }; | ||
|
|
||
| // Act | ||
| store.Put(key, value); | ||
|
|
||
| // Assert | ||
| store.HasKey(key).ShouldBeTrue(); | ||
| store.TryGet(key, out var retrievedValue).ShouldBeTrue(); | ||
| retrievedValue.ShouldBeEquivalentTo(value); | ||
| } |
Copilot
AI
Dec 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test suite lacks coverage for empty set scenarios. Add tests that verify storing and retrieving empty sets (both primitive and string element types) to ensure the serializer handles edge cases correctly, particularly for the FixedSizeSetSerializer used with primitive types.
| [Test] | ||
| public void should_put_and_retrieve_data_with_sets_from_store() | ||
| { | ||
| // Arrange | ||
| using var testFixture = CreateTestFixture<ISet<ProtoNetCacheKey>, ISet<ProtoNetCacheValue>>(); | ||
| var store = testFixture.GetStore<RocksDbGenericStore<ISet<ProtoNetCacheKey>, ISet<ProtoNetCacheValue>>>(); | ||
|
|
||
| // Act | ||
| var cacheKey = Enumerable.Range(0, 100) | ||
| .Select(x => new ProtoNetCacheKey | ||
| { | ||
| Id = x, | ||
| }) | ||
| .ToHashSet(); | ||
|
|
||
| var cacheValue = Enumerable.Range(0, 100) | ||
| .Select(x => new ProtoNetCacheValue | ||
| { | ||
| Id = x, | ||
| Value = $"value-{x}", | ||
| }) | ||
| .ToHashSet(); | ||
|
|
||
| store.Put(cacheKey, cacheValue); | ||
|
|
||
| store.HasKey(cacheKey).ShouldBeTrue(); | ||
| store.TryGet(cacheKey, out var value).ShouldBeTrue(); | ||
| value.ShouldBeEquivalentTo(cacheValue); | ||
| } |
Copilot
AI
Dec 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test suite lacks coverage for empty set scenarios. Add tests that verify storing and retrieving empty sets (both primitive and non-primitive element types) to ensure the serializer handles edge cases correctly.
No description provided.