KeysAndValues 1.0.0
.NET 6.0
This package targets .NET 6.0. The package is compatible with this framework or higher.
.NET Standard 2.0
This package targets .NET Standard 2.0. The package is compatible with this framework or higher.
dotnet add package KeysAndValues --version 1.0.0
NuGet\Install-Package KeysAndValues -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="KeysAndValues" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="KeysAndValues" Version="1.0.0" />
<PackageReference Include="KeysAndValues" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add KeysAndValues --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: KeysAndValues, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package KeysAndValues@1.0.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=KeysAndValues&version=1.0.0
#tool nuget:?package=KeysAndValues&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
KeysAndValues
A simple in-memory sorted key-value store.
Example usage:
using KeysAndValues;
using System.Diagnostics;
// the store
KeyValueStore? kvs = null;
// try to load
var dbpath = Path.Combine(Path.GetTempPath(), "keys-and-values.dat");
if (File.Exists(dbpath))
{
using var fs = File.OpenRead(dbpath);
if (KeyValueStoreSerialization.TryDeserializeStore(fs, out kvs))
{
Console.WriteLine($"Opened existing store " +
$"with {kvs.Count} items " +
$"at sequence {kvs.Sequence}");
}
else
{
Console.WriteLine("The store could not be read!");
}
}
// if we could not load, create new, empty
kvs ??= new();
// set a key
kvs.Set($"key-{Guid.NewGuid()}", $"Now is: {DateTime.Now}");
// keys and values are of type Mem, which
// wraps an immutable block of memory. It has
// many implicit casts. Strings are encoded
// via UTF-8.
Mem memKey = $"key-{Guid.NewGuid()}";
Mem memValue = new byte[] { 1, 2, 3 };
kvs.Set(memKey, memValue);
// Many keys may be set at once.
// This is an atomic change to the store.
var changes = Enumerable.Range(0, 10)
.Select(i => new KeyValuePair<Mem, Mem>($"numbers-{Guid.NewGuid()}", $"Item {i}"));
kvs.Set(changes);
// items can be empty
kvs.Set("emptyitem", default);
Debug.Assert(kvs.ContainsKey("emptyitem"));
// items may be removed
Console.WriteLine($"Count before delete: {kvs.Count} at seq {kvs.Sequence}");
kvs.Delete(["somekey", "emptyitem"]);
Console.WriteLine($"Count after delete: {kvs.Count} at seq {kvs.Sequence}");
// multiple items may be removed
Console.WriteLine($"Count before second delete: {kvs.Count} at seq {kvs.Sequence}");
kvs.Delete(kvs.EnumeratePrefix("numbers-").Select(x => x.Key));
Console.WriteLine($"Count after second delete: {kvs.Count} at seq {kvs.Sequence}");
// As seen above, a key feature is range enumeration.
// Enumeration is thread safe (as all operations are).
// The store may be changed while enumeration is in progress
// and the enumeration will not "see" any changes after the
// call to Enumerate.
kvs.Set("item-1", "1");
kvs.Set("item-2", "2");
kvs.Set("item-3", "3");
kvs.Set("item-4", "4");
var itemsInRange = kvs.Enumerate(
fromKeyInclusive: "item-1",
toKeyExclusive: "item-3");
Debug.Assert(itemsInRange.Count() == 2);
// Each time the store changes, the sequence number is updated.
// Setting or deleting multiple items is one sequence number increment.
Console.WriteLine($"The store sequence number is now {kvs.Sequence}");
Console.WriteLine($"The store contains {kvs.Count} items");
// and then a store may be serialized
var tmpdbpath = Path.GetTempFileName();
using (var wfs = File.Create(tmpdbpath))
{
KeyValueStoreSerialization.SerializeStore(kvs, wfs);
}
// copy over the old db file
File.Copy(tmpdbpath, dbpath, overwrite: true);
File.Delete(tmpdbpath);
// check some stats
var (keyBytes, valueBytes) = kvs.Enumerate().Aggregate(
(keyBytes: 0, valueBytes: 0),
(b, x) => (b.keyBytes + x.Key.Length, b.valueBytes + x.Value.Length));
Console.WriteLine($"The store contains {keyBytes} bytes in keys");
Console.WriteLine($"The store contains {valueBytes} bytes in values");
Console.WriteLine($"Serialized the store to a {new FileInfo(dbpath).Length} byte file");
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- System.Buffers (>= 4.5.0)
- System.Memory (>= 4.5.2)
-
.NETStandard 2.1
- No dependencies.
-
net6.0
- No dependencies.
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 195 | 8/22/2025 |