| Crates.io | matchy-literal-hash |
| lib.rs | matchy-literal-hash |
| version | 2.0.0 |
| created_at | 2025-12-29 07:18:24.654068+00 |
| updated_at | 2025-12-29 07:18:24.654068+00 |
| description | O(1) exact string matching via memory-mapped hash tables (internal) |
| homepage | |
| repository | https://github.com/matchylabs/matchy |
| max_upload_size | |
| id | 2010129 |
| size | 37,912 |
O(1) exact string matching using memory-mapped hash tables with parallel construction.
use matchy_literal_hash::{LiteralHashBuilder, LiteralHash};
use matchy_match_mode::MatchMode;
// Build a hash table
let mut builder = LiteralHashBuilder::new(MatchMode::CaseInsensitive);
builder.add_pattern("example.com", 0);
builder.add_pattern("google.com", 1);
let pattern_data = vec![(0, 100), (1, 200)]; // (pattern_id, data_offset)
let bytes = builder.build(&pattern_data)?;
// Load and query
let hash = LiteralHash::from_buffer(&bytes, MatchMode::CaseInsensitive)?;
assert_eq!(hash.lookup("example.com"), Some(0));
assert_eq!(hash.lookup("EXAMPLE.COM"), Some(0)); // Case-insensitive
[Header - 32 bytes]
magic: "LHSH"
version: 3
entry_count, table_size, num_shards, shard_bits
mappings_offset, table_offset
[Shard Offset Table]
offsets: [u32; num_shards + 1]
[Hash Table - Array of Structs]
entries: [HashEntry; table_size]
hash_lo: u64 // Lower 64 bits of XXH3
hash_hi: u32 // Upper 32 bits of XXH3
pattern_id: u32
[Pattern Mappings]
(pattern_id, data_offset) pairs
matchy-match-mode - Shared MatchMode enumrustc-hash - Fast FxHashMapxxhash-rust - XXH3 implementationrayon - Parallel shard construction