Open-Awesome
CategoriesAlternativesStacksSelf-HostedExplore
Open-Awesome

© 2026 Open-Awesome. Curated for the developer elite.

TermsPrivacyAboutGitHubRSS
  1. Home
  2. C/C++
  3. hat-trie

hat-trie

MITC++v0.7.1

A C++ header-only library implementing a fast and memory-efficient HAT-trie data structure for storing sets and maps of strings.

GitHubGitHub
864 stars122 forks0 contributors

What is hat-trie?

hat-trie is a C++ library that implements the HAT-trie data structure, a cache-conscious trie optimized for storing and querying large sets or maps of strings. It solves the problem of high memory usage in traditional hash tables and tries by compressing common prefixes, offering fast exact and prefix searches with low memory overhead.

Target Audience

C++ developers working with large dictionaries, autocompletion systems, or applications requiring efficient string storage and retrieval, such as search engines, databases, or text processing tools.

Value Proposition

Developers choose hat-trie for its superior memory efficiency and performance in string-heavy workloads, providing a header-only, configurable alternative to standard containers like std::unordered_map while supporting advanced features like prefix searches and serialization.

Overview

C++ implementation of a fast and memory efficient HAT-trie

Use Cases

Best For

  • Storing large dictionaries or word lists with minimal memory usage
  • Implementing autocompletion or search suggestion systems
  • Applications requiring fast prefix searches on string datasets
  • Efficient serialization and deserialization of string maps
  • Scenarios where binary data (including nulls) needs to be stored as keys
  • Optimizing memory in embedded systems or performance-critical C++ applications

Not Ideal For

  • Applications requiring sorted iteration of keys, as hat-trie does not maintain key order
  • Projects with datasets of very short, unique keys where prefix compression offers minimal memory benefit
  • Environments restricted to C++98 or without C++11 support, since hat-trie relies on modern C++ features
  • Use cases demanding constant-time exact lookups with no iterator invalidation, where standard hash tables might be more predictable

Pros & Cons

Pros

Memory-Efficient String Storage

Benchmarks show hat-trie uses up to 3x less memory than std::unordered_map, such as 402.25 MiB vs 1246.60 MiB for the Wikipedia dataset, due to prefix compression.

Built-in Prefix Search

Provides methods like equal_prefix_range and longest_prefix for efficient autocompletion and prefix matching, directly supported in the API as highlighted in the overview.

Header-Only Simplicity

Easy integration as a header-only library; just include the directory, with CMake target support for streamlined build system integration.

Flexible Serialization

Includes serialize and deserialize methods for efficient storage and transmission, with examples for custom serializers using Boost or standard streams.

Configurable Performance Tuning

Parameters like burst_threshold and max_load_factor allow balancing memory and speed; for example, reducing burst_threshold optimizes prefix search performance.

Cons

No Key Ordering

Keys are not stored in sorted order, limiting use cases that require ordered traversal or range queries without additional sorting overhead.

Iterator Invalidation on Modification

Any insert, erase, or update invalidates all iterators, complicating code that relies on stable references during concurrent or iterative operations.

Limited Internationalization Support

Currently only supports char as the character type, with no native handling for wide characters like wchar_t, which may hinder use with Unicode or other encodings.

Boilerplate for Serialization

Serialization requires user-provided function objects, adding complexity compared to libraries with built-in serialization formats out of the box.

Frequently Asked Questions

Quick Stats

Stars864
Forks122
Contributors0
Open Issues14
Last commit5 months ago
CreatedSince 2017

Tags

#autocompletion#trie#data-structures#c-plus-plus#memory-efficient#serialization#cpp#header-only

Built With

C
CMake
C
C++

Included in

C/C++70.6k
Auto-fetched 1 day ago

Related Projects

Parallel HashmapParallel Hashmap

A family of header-only, very fast and memory-friendly hashmap and btree containers.

Stars3,175
Forks307
Last commit24 days ago
CRoaringCRoaring

Roaring bitmaps in C (and C++), with SIMD (AVX2, AVX-512 and NEON) optimizations: used by Apache Doris, ClickHouse, Alibaba Tair, Redpanda, YDB and StarRocks

Stars1,819
Forks314
Last commit1 day ago
robin-hood-hashingrobin-hood-hashing

Fast & memory efficient hashtable based on robin hood hashing for C++11/14/17/20

Stars1,607
Forks157
Last commit3 years ago
robin-maprobin-map

C++ implementation of a fast hash map and hash set using robin hood hashing

Stars1,469
Forks140
Last commit6 months ago
Community-curated · Updated weekly · 100% open source

Found a gem we're missing?

Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.

Submit a projectStar on GitHub