RBTree-0.0.5: Pure haskell Red-Black-Tree implemetation
Safe HaskellSafe-Inferred
LanguageHaskell98

Data.Tree.RBTree

Description

Pure Haskell Red-Black tree implementation

Synopsis

Tree Types

data Color Source #

Color of a Node. Leaf is assumed to be Black.

Constructors

Red 
Black 

Instances

Instances details
Show Color Source #

for distinguish Red/Black, show '*' for Red and nothing for Black.

Instance details

Defined in Data.Tree.RBTree

Methods

showsPrec :: Int -> Color -> ShowS #

show :: Color -> String #

showList :: [Color] -> ShowS #

Eq Color Source # 
Instance details

Defined in Data.Tree.RBTree

Methods

(==) :: Color -> Color -> Bool #

(/=) :: Color -> Color -> Bool #

data RBTree a Source #

Basic RBTree Structure.

Constructors

Node Color a !(RBTree a) !(RBTree a)

A Node that holds an element and has two leaves.

Leaf

A Black leaf.

Instances

Instances details
Show a => Show (RBTree a) Source #

Simply show tree in (), hard to read but easy to parse.

Instance details

Defined in Data.Tree.RBTree

Methods

showsPrec :: Int -> RBTree a -> ShowS #

show :: RBTree a -> String #

showList :: [RBTree a] -> ShowS #

emptyRB :: RBTree a Source #

Gen an empty Tree.

Interval Types

data Interval a Source #

used for range query.

Constructors

Interval (RealOrd a, RealOrd a) 

Instances

Instances details
Show a => Show (Interval a) Source # 
Instance details

Defined in Data.Tree.RBTree

Methods

showsPrec :: Int -> Interval a -> ShowS #

show :: Interval a -> String #

showList :: [Interval a] -> ShowS #

data RealOrd a Source #

Interval value from -INF to +INF.

Constructors

PInfinity

positive infinity

NInfinity

positive infinity

RealValue a

Normal value, not need to be Ord.

Instances

Instances details
Show a => Show (RealOrd a) Source # 
Instance details

Defined in Data.Tree.RBTree

Methods

showsPrec :: Int -> RealOrd a -> ShowS #

show :: RealOrd a -> String #

showList :: [RealOrd a] -> ShowS #

Insertion

(<</) :: Ord a => RBTree a -> a -> RBTree a Source #

Insert Operator for insertOrd

insert :: (a -> a -> Ordering) -> RBTree a -> a -> RBTree a Source #

Insert anything. |you have to provide a compare function.

insertOrd :: Ord a => RBTree a -> a -> RBTree a Source #

Insert 'Ord' things.

insertOrdList :: Ord a => RBTree a -> [a] -> RBTree a Source #

Insert a bunch of 'Ord' things.

Delete

(<<\) :: Ord a => RBTree a -> a -> RBTree a Source #

Delete Operator for deleteOrd

delete :: (a -> a -> Ordering) -> RBTree a -> a -> RBTree a Source #

If there is no relevant element in tree, tree will be returned unmodified.

deleteOrd :: Ord a => RBTree a -> a -> RBTree a Source #

Delete an 'Ord' thing. see delete.

deleteOrdList :: Ord a => RBTree a -> [a] -> RBTree a Source #

Delete a sequence of elements.

Search

(<<?) :: Ord a => RBTree a -> a -> Maybe a Source #

Search operator for searchOrd

search :: (b -> a -> Ordering) -> RBTree a -> b -> Maybe a Source #

search for any thing, you should provide proper compare function.

searchOrd :: Ord a => RBTree a -> a -> Maybe a Source #

Search for 'Ord' things. see search

searchFast :: (b -> a -> Ordering) -> RBTree a -> b -> Maybe a Source #

a faster search function implemetation. strongly recommanded.

searchMax :: Ord a => RBTree a -> Maybe a Source #

Search the Maximum value in the tree, equals to get the right-most element.

searchMin :: Ord a => RBTree a -> Maybe a Source #

Search the Minimum value in the tree, equals to get the left-most element.

searchInterval :: (b -> a -> Ordering) -> RBTree a -> b -> Interval a Source #

Search for a Interval.

For example: tree has 1,3,5,7. search for 3 returns [3,3] that indicates itself search for 4 returns [3,5] indicates that 4 is between the element 3 and 5

The given value be or not be an element of the tree.

searchIntervalOrd :: Ord a => RBTree a -> a -> Interval a Source #

Search 'Ord' things, see searchInterval

Verification

vD :: RBTree a -> Maybe Int Source #

Verify black-depth are all the same. Return Just 'depth' on success, otherwise Nothing.

vR :: RBTree a -> Bool Source #

vR : verify no 'red-red' pattern in x and x's parent