Faster.Map 4.2.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Faster.Map --version 4.2.1                
NuGet\Install-Package Faster.Map -Version 4.2.1                
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="Faster.Map" Version="4.2.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Faster.Map --version 4.2.1                
#r "nuget: Faster.Map, 4.2.1"                
#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.
// Install Faster.Map as a Cake Addin
#addin nuget:?package=Faster.Map&version=4.2.1

// Install Faster.Map as a Cake Tool
#tool nuget:?package=Faster.Map&version=4.2.1                

Faster.Map - A collection of hashmaps (FastMap, DenseMapSIMD and DenseMap)

The goal of Faster is to provide a collection of incredible fast hashmaps that integrates into the .net framework.

About

Faster.Map is a collection of hashmaps with minimal memory overhead and incredibly fast runtime speed. See benchmarks, or try it out yourself. Faster evolved from the fact that C# dictionaries in targetframework 4.0 are terribly slow. So i decided to create my own robinhood hashmap, turns out that this hashmap even performs better than the current dictionary written in .net7.

Get Started

  1. Install nuget package Faster.Map to your project.
dotnet add package Faster.Map

How to use

Faster.Map provides 3 unique hashmaps:

  1. FastMap<Tkey, TValue> is a hashmap which has incredible performance, will only work with numerical keys. Keys need to be unique. Won`t handle hashcollisions

  2. DenseMap<Tkey, TValue> is a hashmap which can be used as a replacement to IDicionary. Default loadfactor is 0.5

  3. DenseMapSIMD<Tkey, TValue> is a next level hashmap using simd intructions. The default loadfactor is 0.9. This allows us to store 15% more entries than a dictionary while maintaining incredible speed. This hashmap is fast and i mean mindblowing fast.

Tested on platforms:

  • x86
  • x64
  • arm
  • arm64

Examples

Default Example

private FastMap<uint, uint> _map = new FastMap<uint, uint>(16);     
  _map.Emplace(1, 50); 
  _map.Remove(1);
  _map.Get(1, out var result);
  _map.Update(1, 51); 
 var result = _map[1];    

DenseMap Example

private DenseMap<uint, uint> _map = new DenseMap<uint, uint>(16);
 _map.Emplace(1, 50); 
 _map.Remove(1);
 _map.Get(1, out var result);
 _map.Update(1, 51);

DenseMapSIMD

private DenseMapSIMD<uint, uint> _map = new DenseMapSIMD<uint, uint>(16);
 _map.Emplace(1, 50); 
 _map.Remove(1);
 _map.Get(1, out var result);
 _map.Update(1, 51);

Benchmark


BenchmarkDotNet=v0.13.1, OS=Windows 10.0.22621
12th Gen Intel Core i5-12500H, 1 CPU, 16 logical and 12 physical cores
.NET SDK=7.0.101
  [Host]     : .NET 7.0.1 (7.0.122.56804), X64 RyuJIT
  Job-HLVSMK : .NET 7.0.1 (7.0.122.56804), X64 RyuJIT

InvocationCount=1  UnrollFactor=1  


### Retrieving a million random generated keys
|         Method |      Mean |     Error |    StdDev |
|--------------- |----------:|----------:|----------:|
|   DenseMapSIMD |  6.224 ms | 0.0860 ms | 0.0762 ms |    
|       DenseMap | 11.873 ms | 0.1705 ms | 0.1595 ms |    
|        FastMap |  7.775 ms | 0.1016 ms | 0.0901 ms |    
| SlimDictionary | 12.174 ms | 0.1368 ms | 0.1279 ms |    
|     Dictionary | 14.816 ms | 0.2798 ms | 0.3331 ms |    

### Adding a million keys
|         Method |     Mean |    Error |   StdDev |   Median |
|--------------- |---------:|---------:|---------:|---------:|
|   DenseMapSIMD | 12.38 ms | 0.600 ms | 1.750 ms | 12.87 ms |
|       DenseMap | 14.10 ms | 0.280 ms | 0.734 ms | 14.18 ms |
|        FastMap | 14.40 ms | 0.286 ms | 0.674 ms | 14.47 ms |
|     Dictionary | 16.80 ms | 0.334 ms | 0.970 ms | 16.77 ms |
| DictionarySlim | 27.29 ms | 0.395 ms | 0.330 ms | 27.21 ms |

### Updating a million keys
|         Method |     Mean |    Error |   StdDev |
|--------------- |---------:|---------:|---------:|
| DenseMapSIMD   |  6.478 ms | 0.1141 ms | 0.1067 ms |
|      FastMap   |  8.170 ms | 0.1086 ms | 0.1016 ms |
|     DenseMap   | 13.394 ms | 0.1897 ms | 0.1682 ms |
|   UpdateSlim   | 12.584 ms | 0.2393 ms | 0.2350 ms |
|   Dictionary   | 15.332 ms | 0.2669 ms | 0.2967 ms |

### Removing a million keys
|         Method |      Mean |     Error |    StdDev |
|--------------- |----------:|----------:|----------:|
| SlimDictionary | 14.49 ms | 0.193 ms | 0.171 ms |
|     Dictionary | 19.58 ms | 0.328 ms | 0.403 ms |
|        FastMap | 15.88 ms | 0.291 ms | 0.272 ms |
|   DenseMapSIMD | 9.903 ms | 0.2949 ms | 0.7972 ms |
|       DenseMap | 13.52 ms | 0.270 ms | 0.420 ms |


### Add and resize
|         Method |     Mean |    Error |   StdDev |
|--------------- |---------:|---------:|---------:|
|   DenseMapSIMD | 15.61 ms | 0.311 ms | 0.763 ms |
|       DenseMap | 23.23 ms | 0.206 ms | 0.172 ms |
|        FastMap | 25.63 ms | 0.293 ms | 0.260 ms |
|     Dictionary | 32.65 ms | 0.647 ms | 1.421 ms |
| DictionarySlim | 25.63 ms | 0.505 ms | 1.348 ms |

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  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 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net7.0

    • No dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Faster.Map:

Package Downloads
Faster.Ioc

Package Description

UPSRestApi

UpsRestApi library for .Net used to access UPS API Catalog to browse products and view documentation.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
6.1.3 37 11/27/2024
6.1.2 73 11/16/2024
6.1.1 98 10/31/2024
6.1.0 95 10/31/2024
6.0.4 116 10/13/2024
6.0.3 172 9/4/2024
6.0.2 107 9/3/2024
6.0.1 100 9/1/2024
6.0.0 130 8/7/2024
5.0.4 975 4/16/2024
5.0.3 491 11/18/2023
5.0.2 225 10/29/2023
5.0.1 141 10/29/2023
5.0.0 162 10/28/2023
4.2.1 308 9/2/2023
4.2.0 2,222 4/24/2023
4.1.6 245 4/24/2023
4.1.5 351 3/19/2023
4.1.4 341 3/14/2023
4.1.3 301 3/14/2023
4.1.2 272 3/14/2023
4.1.1 863 3/10/2023
4.1.0 305 3/9/2023
4.0.9 296 3/9/2023
4.0.8 293 3/9/2023
4.0.7 316 3/6/2023
4.0.6 344 3/3/2023
4.0.5 328 3/1/2023
4.0.4 410 2/24/2023
4.0.3 365 2/23/2023
4.0.2 1,149 1/7/2023
4.0.1 403 1/6/2023
4.0.0 384 1/4/2023
3.0.4.2 750 12/22/2022
3.0.3.9 1,099 12/9/2022
3.0.3.8 762 11/8/2022
3.0.3.7 523 10/27/2022
3.0.3.6 539 10/18/2022
3.0.3.5 438 10/18/2022
3.0.3.4 1,111 9/20/2022
3.0.3.3 1,262 5/19/2022
3.0.3.2 484 5/17/2022
3.0.3.1 477 5/17/2022
3.0.3 479 5/17/2022
3.0.2 494 5/15/2022

Minor bugfixes