pykinos-core
Copyright(c) Nadia Yvette Chambers 2026
LicenseEUPL-1.2
MaintainerNadia Chambers <nadia.yvette.chambers@ik.me>
Stabilityexperimental
Portabilitynon-portable (GHC extensions, primitive arrays)
Safe HaskellNone
LanguageGHC2024

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

FAST Accelerator Structure

data FASTMap k v Source #

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

  • fmSize :: !Int

    Number of stored key-value entries.

  • fmEytzKeys :: !(SmallArray k)

    Keys stored in 1-based Eytzinger breadth-first ordering. Index 0 is unused padding.

  • fmEytzVals :: !(SmallArray v)

    Values aligned with keys in 1-based Eytzinger ordering.

Instances

Instances details
Functor (FASTMap k) Source # 
Instance details

Defined in Pykinos.Tree.FAST

Methods

fmap :: (a -> b) -> FASTMap k a -> FASTMap k b

(<$) :: a -> FASTMap k b -> FASTMap k a

(Eq k, Eq v) => Eq (FASTMap k v) Source # 
Instance details

Defined in Pykinos.Tree.FAST

Methods

(==) :: FASTMap k v -> FASTMap k v -> Bool

(/=) :: FASTMap k v -> FASTMap k v -> Bool

(Show k, Show v) => Show (FASTMap k v) Source # 
Instance details

Defined in Pykinos.Tree.FAST

Methods

showsPrec :: Int -> FASTMap k v -> ShowS

show :: FASTMap k v -> String

showList :: [FASTMap k v] -> ShowS

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 unsafeShiftL 1 (i.e. \(2 \cdot \text{idx}\)) * Right child: (idx unsafeShiftL 1) + 1 (i.e. \(2 \cdot \text{idx} + 1\))

Running time: \(O(\log n)\) with zero pointer dereferences and optimal cacheline utilization.

sizeFAST :: FASTMap k v -> Int Source #

Query the total number of entries in the FASTMap.

Running time: \(O(1)\).