Table of Contents

Slotmaps Documentation

Welcome to the documentation for the Slotmaps library, a C# .NET library designed for slot-based data structures, enabling organized and quick item access using unique and persistent keys.

This library includes features like SlotMap, SecondaryMap, and SparseSecondaryMap. This documentation will guide you through using this library effectively.

Table of Contents 📑

  1. Installation
  2. Getting Started
  3. Contributing
  4. License
  5. Acknowledgement

Installation ⚙️

To use this library, you need to have a C# project that targets .NET 8 or higher. You can install the library from NuGet using the following command:

dotnet add package FlashyDJ.Slotmaps

Getting Started 🚀

Basic Usage

Here's a simple example of creating and using a SlotMap:

using FlashyDJ.Slotmaps;

// Create a SlotMap
SlotMap<string> slotMap = new SlotMap<string>();

// Add some values and get their keys.
SlotKey key1 = slotMap.Add("Item 1");
SlotKey key2 = slotMap.Add("Item 2");
SlotKey key3 = slotMap.Add("Item 3");

// Replacing value from slot
SlotKey newKey2 = slotMap.Insert(key2, "Updated Item 2");

// Access the value using the keys
Console.WriteLine(slotMap[key1]);      // Prints "Item 1"
Console.WriteLine(slotMap[newKey2]);   // Prints "Updated Item 2"
Console.WriteLine(slotMap[key3]);      // Prints "Item 3"
Console.WriteLine(slotMap[key2]);      // Throws KeyNotFoundException

// Remove a value using its key
slotMap.Remove(key1);

// The removed key is no longer valid.
Console.WriteLine(slotMap.ContainsKey(key1)); // Prints "False"

Secondary Maps

In addition to the core SlotMap, this library provides secondary maps like SecondaryMap and SparseSecondaryMap for more advanced data organization. Here's an example of using a SecondaryMap, and iteration of items while maintaining stable references to those items.

using FlashyDJ.Slotmaps;

// Create a SlotMap and a SecondaryMap
SlotMap<string> slotMap = a SlotMap<string>();
SecondaryMap<int> secondaryMap = new SecondaryMap<int>();

// Add values to the SlotMap
SlotKey key1 = slotMap.Add("Item 1");
SlotKey key2 = slotMap.Add("Item 2");

// Insert some values using the keys from the primary map (SlotMap).
secondaryMap.Insert(key1, 42);
secondaryMap.Insert(key2, 56);

// Retrieve items using the keys from the primary map (SlotMap).
Console.WriteLine(secondaryMap[key1]); // Prints "42"
Console.WriteLine(secondaryMap[key2]); // Print "56"

Contributing 👋

This library is open for contributions from anyone who is interested. If you have any ideas, suggestions or bug reports, please open an issue or a pull request on this repository.

License 📋 MIT - License

This library is licensed under the MIT license. See the LICENSE file for more details.

Acknowledgement 💎

This C# library is inspired by the Rust crate slotmap, created by orlp. This adapts the ideas and core concepts of the Rust implementation.