Data.IntMap
data Trie a =
Node (Maybe a) [(Char, Trie a)]
lookup :: String → Trie a → Maybe a
insert :: String → a → Trie a → Trie a
Practical Algorithm to Retrieve Information Coded in Alphanumeric
Int keys
ByteString keys?
two keys: 00011, 00001
type Prefix = Int
type Mask = Int
data IntMap a =
Branch !Prefix !Mask
!(IntMap a) !(IntMap a)
| Leaf !Prefix a
| Empty
highestBitSet ~ bitwise trick -- Borrowed from Haskell's Data.IntMap
highestBitSet :: Int -> Int
highestBitSet n =
case (n .|. shiftR n 1) of
n -> case (n .|. shiftR n 2) of
n -> case (n .|. shiftR n 4) of
n -> case (n .|. shiftR n 8) of
n -> case (n .|. shiftR n 16) of
n -> case (n .|. shiftR n 32) of -- for 64 bit platforms
n -> (n `xor` (shiftR n 1))
Data.Map
n bits of key = 2ⁿ children per node
Created by Tikhon Jelvis.