module Text.Regex.TDFA.IntArrTrieSet where
import Data.Array.IArray(Array,(!),listArray)
data TrieSet v = TrieSet { forall v. TrieSet v -> v
value :: v
, forall v. TrieSet v -> Array Int (TrieSet v)
next :: Array Int (TrieSet v) }
lookupAsc :: TrieSet v -> [Int] -> v
lookupAsc :: forall v. TrieSet v -> [Int] -> v
lookupAsc (TrieSet {value :: forall v. TrieSet v -> v
value=v
v,next :: forall v. TrieSet v -> Array Int (TrieSet v)
next=Array Int (TrieSet v)
n}) =
(\[Int]
keys -> case [Int]
keys of [] -> v
v
(Int
key:[Int]
keys') -> forall v. TrieSet v -> [Int] -> v
lookupAsc (Array Int (TrieSet v)
nforall (a :: * -> * -> *) e i.
(IArray a e, Ix i) =>
a i e -> i -> e
!Int
key) [Int]
keys')
fromBounds :: (Int,Int)
-> ([Int] -> v)
-> TrieSet v
fromBounds :: forall v. (Int, Int) -> ([Int] -> v) -> TrieSet v
fromBounds (Int
start,Int
stop) [Int] -> v
keysToValue = ([Int] -> [Int]) -> Int -> TrieSet v
build forall a. a -> a
id Int
start where
build :: ([Int] -> [Int]) -> Int -> TrieSet v
build [Int] -> [Int]
keys Int
low = TrieSet { value :: v
value = [Int] -> v
keysToValue ([Int] -> [Int]
keys [])
, next :: Array Int (TrieSet v)
next = forall (a :: * -> * -> *) e i.
(IArray a e, Ix i) =>
(i, i) -> [e] -> a i e
listArray (Int
low,Int
stop)
[([Int] -> [Int]) -> Int -> TrieSet v
build ([Int] -> [Int]
keysforall b c a. (b -> c) -> (a -> b) -> a -> c
.(Int
xforall a. a -> [a] -> [a]
:)) (forall a. Enum a => a -> a
succ Int
x) | Int
x <- [Int
low..Int
stop] ] }
fromSinglesMerge :: v
-> (v->v->v)
-> (Int,Int)
-> (Int->v)
-> TrieSet v
fromSinglesMerge :: forall v.
v -> (v -> v -> v) -> (Int, Int) -> (Int -> v) -> TrieSet v
fromSinglesMerge v
emptyValue v -> v -> v
mergeValues (Int, Int)
bound Int -> v
keyToValue = TrieSet v
trieSet where
trieSet :: TrieSet v
trieSet = forall v. (Int, Int) -> ([Int] -> v) -> TrieSet v
fromBounds (Int, Int)
bound [Int] -> v
keysToValue'
keysToValue' :: [Int] -> v
keysToValue' [Int]
keys =
case [Int]
keys of
[] -> v
emptyValue
[Int
key] -> Int -> v
keyToValue Int
key
[Int]
_ -> v -> v -> v
mergeValues ([Int] -> v
keysToValue (forall a. [a] -> [a]
init [Int]
keys)) ([Int] -> v
keysToValue [forall a. [a] -> a
last [Int]
keys])
keysToValue :: [Int] -> v
keysToValue = forall v. TrieSet v -> [Int] -> v
lookupAsc TrieSet v
trieSet
fromSinglesSum :: ([v]->v)
-> (Int,Int)
-> (Int->v)
-> TrieSet v
fromSinglesSum :: forall v. ([v] -> v) -> (Int, Int) -> (Int -> v) -> TrieSet v
fromSinglesSum [v] -> v
mergeValues (Int, Int)
bound Int -> v
keyToValue = TrieSet v
trieSet where
trieSet :: TrieSet v
trieSet = forall v. (Int, Int) -> ([Int] -> v) -> TrieSet v
fromBounds (Int, Int)
bound [Int] -> v
keysToValue'
keysToValue' :: [Int] -> v
keysToValue' = [v] -> v
mergeValues forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map Int -> v
keyToValue