| Copyright | (c) Nadia Yvette Chambers 2026 |
|---|---|
| License | EUPL-1.2 |
| Maintainer | Nadia Chambers <nadia.yvette.chambers@ik.me> |
| Stability | experimental |
| Portability | non-portable (GHC extensions, primitive arrays) |
| Safe Haskell | None |
| Language | GHC2024 |
Pykinos.Tree.FAST
Description
Implements the Fast Architecture Sensitive Tree (FAST) layout derived from Kim et al. (SIGMOD 2010), "FAST: Fast Architecture Sensitive Tree Search on Modern CPUs and GPUs".
Architectural Rationale
Traditional balanced binary trees (such as red-black trees or AVL trees) and even cache-conscious B-trees incur pointer-chasing overhead across non-contiguous heap objects: 1. Each branch navigation traverses a heap pointer to a separate cache line. 2. Branch predictors struggle with binary traversal patterns. 3. Hardware memory prefetchers cannot predict irregular memory strides.
FAST resolves these hardware bottlenecks by flattening an ordered collection into a 1-based Eytzinger (breadth-first array) layout: * Root resides at index 1. * For any node at index \(i\), its left child is at \(2i\) and right child is at \(2i + 1\). * Children of consecutive nodes are contiguous in memory, allowing hardware streaming prefetchers to anticipate memory accesses across levels. * Tree levels map cleanly into L1/L2 cache lines with zero pointer indirection.
FAST structures in Pykinos are immutable snapshots materialized by freezeFAST
from a mutable or transient BPlusMap, providing high-throughput read-only
accelerators for symbol lookups and index sweeps.
Synopsis
- data FASTMap k v = FASTMap {
- fmSize :: !Int
- fmEytzKeys :: !(SmallArray k)
- fmEytzVals :: !(SmallArray v)
- freezeFAST :: BPlusMap k v -> FASTMap k v
- lookupFAST :: Ord k => k -> FASTMap k v -> Maybe v
- sizeFAST :: FASTMap k v -> Int
FAST Accelerator Structure
Fast Architecture Sensitive Tree (FAST) cache-line-blocked array.
Flattened 1-based Eytzinger array layout representing a perfectly balanced
complete search tree in contiguous unboxed SmallArray slices.
Constructors
| FASTMap | |
Fields
| |
Construction & Freezing
freezeFAST :: BPlusMap k v -> FASTMap k v Source #
Freeze an ordered BPlusMap into a contiguous cache-line-blocked FASTMap.
Traverses the B+ tree in ascending key order via an in-order traversal and writes elements directly into 1-based Eytzinger breadth-first slots in a single \(O(n)\) pass.
Running time: \(O(n)\) where \(n\) is the number of elements in the tree.
Memory footprint: \(2 \times (n + 1)\) slots in two contiguous SmallArray buffers.
Queries
lookupFAST :: Ord k => k -> FASTMap k v -> Maybe v Source #
Branch-minimized binary search lookup over the contiguous Eytzinger array.
Navigates down the implicit binary tree using bitwise arithmetic:
* Left child: idx (i.e. \(2 \cdot \text{idx}\))
* Right child: unsafeShiftL 1(idx (i.e. \(2 \cdot \text{idx} + 1\))unsafeShiftL 1) + 1
Running time: \(O(\log n)\) with zero pointer dereferences and optimal cacheline utilization.