Safe Haskell | None |
---|---|
Language | Haskell2010 |
Fair implementation of the Treap
data structure that uses random
generator for priorities.
Synopsis
- data RTreap m a = RTreap {
- rTreapGen :: !PureMT
- rTreapTree :: !(Treap m a)
- emptyWithGen :: PureMT -> RTreap m a
- oneWithGen :: Measured m a => PureMT -> a -> RTreap m a
- empty :: RTreap m a
- one :: Measured m a => a -> RTreap m a
- size :: RTreap m a -> Int
- at :: Int -> RTreap m a -> Maybe a
- query :: forall m a. Measured m a => Int -> Int -> RTreap m a -> m
- splitAt :: forall m a. Measured m a => Int -> RTreap m a -> (RTreap m a, RTreap m a)
- merge :: Measured m a => RTreap m a -> RTreap m a -> RTreap m a
- take :: forall m a. Measured m a => Int -> RTreap m a -> RTreap m a
- drop :: forall m a. Measured m a => Int -> RTreap m a -> RTreap m a
- rotate :: forall m a. Measured m a => Int -> RTreap m a -> RTreap m a
- insert :: forall m a. Measured m a => Int -> a -> RTreap m a -> RTreap m a
- delete :: forall m a. Measured m a => Int -> RTreap m a -> RTreap m a
- withTreap :: (Treap m a -> r) -> RTreap m a -> r
- overTreap :: (Treap m a -> Treap m a) -> RTreap m a -> RTreap m a
- prettyPrint :: forall m a. (Coercible m a, Show a) => RTreap m a -> IO ()
Data structure
Specialized version of Treap
where priority is
generated by the stored random generator.
RTreap | |
|
Instances
Monoid m => Measured m (RTreap m a) Source # | \( O(1) \). Takes cached value from the root. |
Defined in Treap.Rand | |
Foldable (RTreap m) Source # | |
Defined in Treap.Rand fold :: Monoid m0 => RTreap m m0 -> m0 # foldMap :: Monoid m0 => (a -> m0) -> RTreap m a -> m0 # foldr :: (a -> b -> b) -> b -> RTreap m a -> b # foldr' :: (a -> b -> b) -> b -> RTreap m a -> b # foldl :: (b -> a -> b) -> b -> RTreap m a -> b # foldl' :: (b -> a -> b) -> b -> RTreap m a -> b # foldr1 :: (a -> a -> a) -> RTreap m a -> a # foldl1 :: (a -> a -> a) -> RTreap m a -> a # elem :: Eq a => a -> RTreap m a -> Bool # maximum :: Ord a => RTreap m a -> a # minimum :: Ord a => RTreap m a -> a # | |
Measured m a => IsList (RTreap m a) Source # | Pure implementation of
|
(Eq m, Eq a) => Eq (RTreap m a) Source # | \( O(n) \). This instance doesn't compare random generators inside trees. |
(Show m, Show a) => Show (RTreap m a) Source # | |
Generic (RTreap m a) Source # | |
(NFData m, NFData a) => NFData (RTreap m a) Source # | |
Defined in Treap.Rand | |
type Rep (RTreap m a) Source # | |
Defined in Treap.Rand type Rep (RTreap m a) = D1 (MetaData "RTreap" "Treap.Rand" "treap-0.0.0.0-5jWw5ZFdWFjIs5c8K2QNdd" False) (C1 (MetaCons "RTreap" PrefixI True) (S1 (MetaSel (Just "rTreapGen") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 PureMT) :*: S1 (MetaSel (Just "rTreapTree") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 (Treap m a)))) | |
type Item (RTreap m a) Source # | |
Defined in Treap.Rand |
Smart constructors
emptyWithGen :: PureMT -> RTreap m a Source #
\( O(1) \). Create empty RTreap
with given random generator.
oneWithGen :: Measured m a => PureMT -> a -> RTreap m a Source #
\( O(1) \). Create singleton RTreap
with given random generator.
one :: Measured m a => a -> RTreap m a Source #
\( O(1) \). Create singleton RTreap
using random generator with seed 0
.
Query functions
size :: RTreap m a -> Int Source #
\( O(1) \). Returns the size of the RTreap
.
Properties:
- \( \forall (t\ ::\ \mathrm{Treap}\ m\ a)\ .\ \mathrm{size}\ t \geqslant 0 \)
at :: Int -> RTreap m a -> Maybe a Source #
\( O(\log \ n) \). Lookup a value by a given key inside RTreap
.
query :: forall m a. Measured m a => Int -> Int -> RTreap m a -> m Source #
\( O(\log \ n) \). Return value of monoidal accumulator on a segment [l, r)
.
Cuts and joins
Modification functions
insert :: forall m a. Measured m a => Int -> a -> RTreap m a -> RTreap m a Source #
\( O(\log \ n) \). Insert a value into RTreap
by given key.