| 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.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:
- **
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. - **
ARTNode16(5 to 16 children):** Stores up to 16 child pointers alongside 16 sorted key bytes. - **
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. - **
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
- data ARTIntMap a
- = ARTEmpty
- | ARTLeaf !Int a
- | ARTNode4 !Int !Int !(PrimArray Word8) !(SmallArray (ARTIntMap a))
- | ARTNode16 !Int !Int !(PrimArray Word8) !(SmallArray (ARTIntMap a))
- | ARTNode48 !Int !Int !(PrimArray Word8) !(SmallArray (ARTIntMap a))
- | ARTNode256 !Int !Int !(SmallArray (ARTIntMap a))
- emptyART :: ARTIntMap a
- singletonART :: Int -> a -> ARTIntMap a
- artFromList :: [(Int, a)] -> ARTIntMap a
- artLookup :: Int -> ARTIntMap a -> Maybe a
- artMember :: Int -> ARTIntMap a -> Bool
- artToList :: ARTIntMap a -> [(Int, a)]
- artKeysSet :: ARTIntMap a -> RoaringIntSet
- artInsert :: Int -> a -> ARTIntMap a -> ARTIntMap a
- artInsertWith :: (a -> a -> a) -> Int -> a -> ARTIntMap a -> ARTIntMap a
- artDelete :: Int -> ARTIntMap a -> ARTIntMap a
ART IntMap Type
Adaptive Radix Tree (ART) IntMap with 4-tier span fanout:
ARTLeaf: Path-compressed single key-value leaf.ARTNode4: 1..4 children (unboxedWord8key bytes +SmallArraychildren).ARTNode16: 5..16 children (sortedWord8key bytes +SmallArraychildren).ARTNode48: 17..48 children (256-byte direct index table + up to 48 children).ARTNode256: 49..256 children (direct 256-slotSmallArray).
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
| Functor ARTIntMap Source # | |
| Foldable ARTIntMap Source # | |
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 elem :: Eq a => a -> ARTIntMap a -> Bool maximum :: Ord a => ARTIntMap a -> a minimum :: Ord a => ARTIntMap a -> a | |
| Traversable ARTIntMap Source # | |
| Eq a => Eq (ARTIntMap a) Source # | |
| Show a => Show (ARTIntMap a) Source # | |
Construction & Empty Maps
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)\).