| Crates.io | bhc-data-structures |
| lib.rs | bhc-data-structures |
| version | 0.2.1 |
| created_at | 2026-01-25 17:53:05.567592+00 |
| updated_at | 2026-01-25 18:25:52.680429+00 |
| description | Common data structures for the BHC compiler |
| homepage | |
| repository | https://github.com/raskell-io/bhc |
| max_upload_size | |
| id | 2069181 |
| size | 21,279 |
Common data structures for the Basel Haskell Compiler.
This crate provides type aliases and wrappers around commonly used data structures, ensuring consistent hashing performance across the compiler. It standardizes on FxHash for fast, non-cryptographic hashing.
| Type | Description |
|---|---|
FxHashMap<K, V> |
Hash map using FxHasher (fast, deterministic) |
FxHashSet<T> |
Hash set using FxHasher |
FxIndexMap<K, V> |
Insertion-ordered hash map |
FxIndexSet<T> |
Insertion-ordered hash set |
| Type | Description |
|---|---|
TinyVec<T> |
SmallVec optimized for 0-4 elements inline |
SmallVec8<T> |
SmallVec optimized for 0-8 elements inline |
| Type | Description |
|---|---|
WorkQueue<T> |
Work queue for graph traversals (dedup built-in) |
FrozenMap<K, V> |
Immutable map for read-only access |
UnionFind |
Disjoint set data structure |
use bhc_data_structures::{FxHashMap, FxHashSet, FxHashMapExt, WorkQueue};
// Create collections using the extension traits
let mut map: FxHashMap<String, i32> = FxHashMap::new();
map.insert("key".to_string(), 42);
let mut set: FxHashSet<i32> = FxHashSet::with_capacity(100);
set.insert(1);
// Work queue automatically deduplicates
let mut wq: WorkQueue<i32> = WorkQueue::new();
assert!(wq.push(1)); // true: first time
assert!(!wq.push(1)); // false: already seen
assert!(wq.push(2)); // true: new item
while let Some(item) = wq.pop() {
// Process item, potentially pushing more
if item < 10 {
wq.push(item + 1);
}
}
use bhc_data_structures::UnionFind;
let mut uf = UnionFind::new(5);
uf.union(0, 1);
uf.union(2, 3);
uf.union(1, 3);
assert!(uf.same_set(0, 3)); // All connected
assert!(!uf.same_set(0, 4)); // 4 is separate
FxHash is optimized for small keys (integers, short strings) which are common in compilers:
This crate also re-exports commonly used types:
IndexMap, IndexSet from indexmapMutex, RwLock from parking_lotSmallVec from smallvecFxHashMap/FxHashSet over std::collections::HashMap/HashSetFxIndexMap/FxIndexSet when iteration order mattersTinyVec for fields that are usually 0-4 elementsWorkQueue for BFS/worklist algorithmsbhc-typeck - Uses UnionFind for type unificationbhc-core - Uses FxHashMap for variable environmentsbhc-query - Uses WorkQueue for incremental computation