Home

Awesome

StringDB

<div align="center"> <img src="https://rawcdn.githack.com/SirJosh3917/StringDB/master/icons/banner_ad.png" alt="StringDB" />

Build Status Test Status Nuget Version Nuget Downloads

</div>

Install-Package StringDB

Introduction

StringDB is a key/value pair store with a friendly API to use as little RAM and space as possible.

Verify the claims for yourself:

Api

Enumerate over a database and it's values, the fastest, by enumerating over it optimally

using var db = new DatabaseBuilder()
	.UseIODatabase(StringDBVersion.Latest, "database.db", out var optimalTokenSource)
	.WithBuffer(1000)
	.WithTranform(StringTransformation.Default, StringTransformation.Default);
	
foreach (var (key, value) in db.EnumerateOptimally(optimalTokenSource))
{
	// do something with the key and value
}

Use fluent extensions to create a database:

using IDatabase<string, string> db = new DatabaseBuilder()
    .UseIODatabase(StringDBVersion.Latest, "database.db")
    .WithBuffer(1000)
    .WithTransform(StringTransformation.Default, StringTransformation.Default);

using IDatabase<int, string> memDb = new DatabaseBuilder()
    .UseMemoryDatabase<int, string>();

Use the IDatabase interface to interface with databases

void InsertGreeting(IDatabase<string, string> database, string user)
{
    database.Insert(user, $"Greetings, {user}!");
}

And inherit BaseDatabase to create your own IDatabases with minimal effort

public class TestDatabase : BaseDatabase<int, string>
{
    private class LazyValue : ILazyLoader<string>
    {
        private readonly string _value;
        public LazyValue(int value) => _value = value.ToString();
        public string Load() => _value;
        public void Dispose() {}
    }
	
	public override void Dispose() {}

    protected override void InsertRange(KeyValuePair<int, string>[] items)
    {
        foreach(var item in items)
        {
            Console.WriteLine($"{item.Key}: {item.Value}");
        }
    }

    protected override IEnumerable<KeyValuePair<int, ILazyLoader<string>>> Evaluate()
    {
        for(var i = 0; i < int.MaxValue)
        {
            yield return KeyValuePair.Create(i, new LazyValue(i));
        }
    }
}

Tiny icon_tiny

StringDB is tiny. Use tiny amounts of RAM, and tiny amounts of space.

StringDB 10.0.0 file size: single inserts, 128 byte keys, 1024 byte values

Chart

InsertsSize (in KB, 1000 bytes)Absolute Minimum Size PossibleStringDB Overhead Percentage
11.172 KB1.152 KB1.706485%
5058.208 KB57.6 KB1.04453%
100116.408 KB115.2 KB1.037729%

This chart shows the size of a StringDB file after multiple single inserts. Every key is 128 bytes long, and every value is 1024 bytes long. By doing single inserts, file size is dramatically affected due to the additional overhead for the index chain.

StringDB 10.0.0 file size: insert range, 128 byte keys, 1024 byte values

Chart

Elements in Insert RangeSize (in KB, 1000 bytes)Absolute Minimum Size PossibleStringDB Overhead Percentage
11.172 KB1.152 KB1.706485%
5057.963 KB57.6 KB0.626262%
100115.913 KB115.2 KB0.615117%

This chart shows the size of a StringDB file after a single insert range with the amount of items specified.

Addons

Official addon support will be maintained for these libraries.

Issues welcomed!

Don't be afraid to make an issue about anything and everything!

It's an honour to have you use this library, and feedback is needed to make this the greatest it can be.

Need immediate assistence? Join the discord!