HyperTrieCore 1.1.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package HyperTrieCore --version 1.1.1
                    
NuGet\Install-Package HyperTrieCore -Version 1.1.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="HyperTrieCore" Version="1.1.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="HyperTrieCore" Version="1.1.1" />
                    
Directory.Packages.props
<PackageReference Include="HyperTrieCore" />
                    
Project file
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 HyperTrieCore --version 1.1.1
                    
#r "nuget: HyperTrieCore, 1.1.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.
#:package HyperTrieCore@1.1.1
                    
#: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=HyperTrieCore&version=1.1.1
                    
Install as a Cake Addin
#tool nuget:?package=HyperTrieCore&version=1.1.1
                    
Install as a Cake Tool

CI codecov NuGet Downloads NuGet Version GitHub License Rust C#

Alt text

HyperTrie

HyperTrie is a hyper optimized C# prefix tree written in Rust. It is currently the fastest C# Trie implementation, about 1,300% faster (92.71% less time) than TrieNet.Core 😮‍💨

Why make this?

Well, I wanted to try optimizing some of the hot paths in one of my libraries Octane Downloader by rewritting them in Rust, but in order to do that, I needed a simpler project to experiment with multi-target builds and including native rust code in a Nuget package. Then I proceeded to optimize the hell out of it for no reason just to see how far I could go. I'm sure there potentially more optimizations to make, so if you see anything feel free to open a PR.

Why not use a HashMap?

Because of the additional overhead of hashing and collisions. It's faster to just use an array. Although, this leads to poor space complexity due to sparse arrays everywhere, which is why I decided to only support 26 characters.

Why a bloom filter?

This is my favorite data structure, and it made perfect sense here since it will never give false negatives. It seemed like the obvious choice to side step hashing and checking if an entry exists in the Trie.

Installation

dotnet add package HyperTrieCore --version 1.0.27

Example

const string url = "https://raw.githubusercontent.com/dolph/dictionary/master/enable1.txt";
var client = new HttpClient();
var content = client.GetStringAsync(url).Result;
var allWords = content.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.ToLower().Trim()).ToList();
var trieNative = new TrieNative(allWords.Count(), 3);
trieNative.BulkInsert(allWords);

Benchmark


BenchmarkDotNet v0.15.8, macOS Tahoe 26.1 (25B78) [Darwin 25.1.0]
Apple M1, 1 CPU, 8 logical and 8 physical cores
.NET SDK 10.0.201
  [Host] : .NET 8.0.0 (8.0.0, 8.0.23.53103), Arm64 RyuJIT armv8.0-a

Toolchain=InProcessEmitToolchain  

Method Mean Error StdDev Median Rank Gen0 Gen1 Gen2 Allocated
'TrieNet (C#)' 223.19 ms 3.119 ms 2.917 ms 222.76 ms 2 19500.0000 8000.0000 3000.0000 107064.97 KB
'HyperTrie (Native)' 16.27 ms 0.325 ms 0.872 ms 15.93 ms 1 - - - 85.25 KB

Limitations

  1. No OSX64 support, the Rust code uses GXHash and the Github actions runner does not support the necessary CPU instruction sets 😦
  2. To maximize performance it only supports 26 ASCII characters (A-Z), this is optimal for usecases such as a dictionary or spellcheck applications but not really useful for something like checking available usernames.

Local development

Building is simplified via Nuke. Use the following commands:

./build.sh --help         # Show all available targets
./build.sh Compile        # Build the C# projects (Default target)
./build.sh BuildRustAll   # Build Rust native libraries for all platforms (requires `cargo cross`)
./build.sh Pack           # Compiles all C# libraries and generates .nupkg NuGet files
./build.sh PublishNuGet   # Pack and push packages to NuGet.org (Requires API key)

Build Outputs This project relies on MSBuild UseArtifactsOutput and maps all builds into a centralized artifacts directory. After compilation, check the artifacts/ folder at the repository root. Native Rust binary artifacts will be cleanly routed to artifacts/native/, while bundled NuGet files are pushed to artifacts/packages/.

License

MIT License

Copyright (c) 2025 Greg James

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Product 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 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 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 is compatible.  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 is compatible.  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 netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen 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.

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.1.2 86 4/12/2026
1.1.1 92 4/12/2026
1.1.0 91 4/12/2026
1.0.34-beta.1 45 4/12/2026
1.0.33 87 4/12/2026
1.0.33-beta.1 43 4/11/2026
1.0.32 90 4/11/2026
1.0.32-beta.7 40 4/11/2026
1.0.32-beta.5 38 4/11/2026
1.0.32-beta.4 47 4/11/2026
1.0.31 204 7/29/2025
1.0.30 173 7/29/2025
1.0.29 179 7/29/2025
1.0.28 169 7/29/2025
1.0.27 178 7/29/2025
1.0.21 176 7/29/2025
1.0.0 86 4/11/2026