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.IntMap.ART

Description

Implements the Adaptive Radix Tree (ART) space-efficient radix tree layout derived from Leis et al. (ICDE 2013), "The Adaptive Radix Tree: ARTful Indexing for Main Memory Databases".

Architectural Mechanics

Traditional radix trees (tries) face a trade-off between span width and space consumption: * Large spans (e.g. 256 children per node) waste significant memory on sparse branches. * Small spans (e.g. 2 or 4 children) create tall trees requiring excessive pointer hops.

ART solves this dynamically by employing 4 distinct node structures that expand and adapt dynamically based on child count:

  1. **ARTNode4 (1 to 4 children):** Stores up to 4 child pointers alongside an unboxed 4-byte key array. Search executes via a linear scan over the 4-byte array.
  2. **ARTNode16 (5 to 16 children):** Stores up to 16 child pointers alongside 16 sorted key bytes.
  3. **ARTNode48 (17 to 48 children):** Stores a 256-byte direct lookup table mapping byte values to child array indices (0..47), using 255 as the empty sentinel. Child pointers reside in a compact 48-element array.
  4. **ARTNode256 (49 to 256 children):** Full direct lookup array of 256 child pointers indexed directly by byte value.

Path Compression

Single-child subtrees are collapsed into path-compressed prefixes (pref and sh), ensuring tree height is bounded strictly by key length (up to 8 bytes for 64-bit Int keys).

Synopsis

ART IntMap Type

data ARTIntMap a Source #

Adaptive Radix Tree (ART) IntMap with 4-tier span fanout:

Constructors

ARTEmpty 
ARTLeaf !Int a

Path-compressed leaf storing full 64-bit key and associated value.

ARTNode4 !Int !Int !(PrimArray Word8) !(SmallArray (ARTIntMap a))

Small node storing 1..4 child pointers.

ARTNode16 !Int !Int !(PrimArray Word8) !(SmallArray (ARTIntMap a))

Medium node storing 5..16 child pointers.

ARTNode48 !Int !Int !(PrimArray Word8) !(SmallArray (ARTIntMap a))

Large node storing 17..48 child pointers with 256-byte index map.

ARTNode256 !Int !Int !(SmallArray (ARTIntMap a))

Full 256-slot direct-indexed radix node.

Instances

Instances details
Functor ARTIntMap Source # 
Instance details

Defined in Pykinos.IntMap.ART

Methods

fmap :: (a -> b) -> ARTIntMap a -> ARTIntMap b

(<$) :: a -> ARTIntMap b -> ARTIntMap a

Foldable ARTIntMap Source # 
Instance details

Defined in Pykinos.IntMap.ART

Methods

fold :: Monoid m => ARTIntMap m -> m

foldMap :: Monoid m => (a -> m) -> ARTIntMap a -> m

foldMap' :: Monoid m => (a -> m) -> ARTIntMap a -> m

foldr :: (a -> b -> b) -> b -> ARTIntMap a -> b

foldr' :: (a -> b -> b) -> b -> ARTIntMap a -> b

foldl :: (b -> a -> b) -> b -> ARTIntMap a -> b

foldl' :: (b -> a -> b) -> b -> ARTIntMap a -> b

foldr1 :: (a -> a -> a) -> ARTIntMap a -> a

foldl1 :: (a -> a -> a) -> ARTIntMap a -> a

toList :: ARTIntMap a -> [a]

null :: ARTIntMap a -> Bool

length :: ARTIntMap a -> Int

elem :: Eq a => a -> ARTIntMap a -> Bool

maximum :: Ord a => ARTIntMap a -> a

minimum :: Ord a => ARTIntMap a -> a

sum :: Num a => ARTIntMap a -> a

product :: Num a => ARTIntMap a -> a

Traversable ARTIntMap Source # 
Instance details

Defined in Pykinos.IntMap.ART

Methods

traverse :: Applicative f => (a -> f b) -> ARTIntMap a -> f (ARTIntMap b)

sequenceA :: Applicative f => ARTIntMap (f a) -> f (ARTIntMap a)

mapM :: Monad m => (a -> m b) -> ARTIntMap a -> m (ARTIntMap b)

sequence :: Monad m => ARTIntMap (m a) -> m (ARTIntMap a)

Eq a => Eq (ARTIntMap a) Source # 
Instance details

Defined in Pykinos.IntMap.ART

Methods

(==) :: ARTIntMap a -> ARTIntMap a -> Bool

(/=) :: ARTIntMap a -> ARTIntMap a -> Bool

Show a => Show (ARTIntMap a) Source # 
Instance details

Defined in Pykinos.IntMap.ART

Methods

showsPrec :: Int -> ARTIntMap a -> ShowS

show :: ARTIntMap a -> String

showList :: [ARTIntMap a] -> ShowS

Construction & Empty Maps

emptyART :: ARTIntMap a Source #

Construct an empty Adaptive Radix Tree.

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

singletonART :: Int -> a -> ARTIntMap a Source #

Construct a single-element Adaptive Radix Tree.

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

artFromList :: [(Int, a)] -> ARTIntMap a Source #

Construct an Adaptive Radix Tree from a list of key-value associations.

Running time: \(O(n \cdot k)\).

Queries

artLookup :: Int -> ARTIntMap a -> Maybe a Source #

Lookup a value associated with key k in the Adaptive Radix Tree.

Running time: \(O(k)\) where \(k \le 8\) bytes for 64-bit keys.

artMember :: Int -> ARTIntMap a -> Bool Source #

Check whether key k is a member of the Adaptive Radix Tree.

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

artToList :: ARTIntMap a -> [(Int, a)] Source #

Convert an Adaptive Radix Tree into a list of key-value associations.

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

artKeysSet :: ARTIntMap a -> RoaringIntSet Source #

Extract all keys in the tree into a compressed RoaringIntSet.

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

Insertion & Deletion

artInsert :: Int -> a -> ARTIntMap a -> ARTIntMap a Source #

Insert a key-value association into the ART, replacing any existing value.

Running time: \(O(k)\) where \(k \le 8\) steps.

artInsertWith :: (a -> a -> a) -> Int -> a -> ARTIntMap a -> ARTIntMap a Source #

Insert with a combining function for resolving existing values.

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

artDelete :: Int -> ARTIntMap a -> ARTIntMap a Source #

Delete a key and its associated value from the Adaptive Radix Tree.

Running time: \(O(n)\) via rebuild.