Permalink
Browse files

ordering.

  • Loading branch information...
1 parent 440012a commit 36f259e36c2b320aa37bbbae9577e01fd8a27118 @kazu-yamamoto committed May 16, 2012
Showing with 45 additions and 45 deletions.
  1. +13 −13 Data/Set/LLRBTree.hs
  2. +13 −13 Data/Set/RBTree.hs
  3. +6 −6 Data/Set/Splay.hs
  4. +13 −13 Data/Set/WBTree.hs
View
@@ -112,7 +112,7 @@ singleton x = Node B 1 Leaf x Leaf
----------------------------------------------------------------
-{-| Creating a tree from a list. O(N log N)
+{-| Creating a tree from a list. Worst-case: O(N log N)
>>> empty == fromList []
True
@@ -127,7 +127,7 @@ fromList = foldl' (flip insert) empty
----------------------------------------------------------------
-{-| Creating a list from a tree. O(N)
+{-| Creating a list from a tree. Worst-case: O(N)
>>> toList (fromList [5,3])
[3,5]
@@ -221,7 +221,7 @@ turnB' (Node _ h l x r) = Node B h l x r
----------------------------------------------------------------
-{-| Finding the minimum element. O(log N)
+{-| Finding the minimum element. Worst-case: O(log N)
>>> minimum (fromList [3,5,1])
1
@@ -234,7 +234,7 @@ minimum (Node _ _ Leaf x _) = x
minimum (Node _ _ l _ _) = minimum l
minimum _ = error "minimum"
-{-| Finding the maximum element. O(log N)
+{-| Finding the maximum element. Worst-case: O(log N)
>>> maximum (fromList [3,5,1])
5
@@ -297,7 +297,7 @@ isLeftLean (Node _ _ r _ l) = isLeftLean r && isLeftLean l
----------------------------------------------------------------
-{-| Insertion. O(log N)
+{-| Insertion. Worst-case: O(log N)
>>> insert 5 (fromList [5,3]) == fromList [3,5]
True
@@ -332,7 +332,7 @@ balanceR c h l x r = Node c h l x r
----------------------------------------------------------------
-{-| Deleting the minimum element. O(log N)
+{-| Deleting the minimum element. Worst-case: O(log N)
>>> deleteMin (fromList [5,3,7]) == fromList [5,7]
True
@@ -470,7 +470,7 @@ hardMax _ = error "hardMax"
----------------------------------------------------------------
-{-| Deleting this element from a tree. O(log N)
+{-| Deleting this element from a tree. Worst-case: O(log N)
>>> delete 5 (fromList [5,3]) == singleton 3
True
@@ -535,7 +535,7 @@ deleteEQ _ _ _ _ _ _ = error "deleteEQ"
-- Set operations
----------------------------------------------------------------
-{-| Joining two trees with an element. O(log N)
+{-| Joining two trees with an element. Worst-case: O(log N)
Each element of the left tree must be less than the element.
Each element of the right tree must be greater than the element.
@@ -569,7 +569,7 @@ joinGT _ _ _ _ = error "joinGT"
----------------------------------------------------------------
-{-| Merging two trees. O(log N)
+{-| Merging two trees. Worst-case: O(log N)
Each element of the left tree must be less than each element of
the right tree. Both trees must have black root.
@@ -620,7 +620,7 @@ mergeEQ _ _ = error "mergeEQ"
----------------------------------------------------------------
-{-| Splitting a tree. O(log N)
+{-| Splitting a tree. Worst-case: O(log N)
>>> split 2 (fromList [5,3]) == (empty, fromList [3,5])
True
@@ -643,7 +643,7 @@ split kx (Node _ _ l x r) = case compare kx x of
----------------------------------------------------------------
-{-| Creating a union tree from two trees. O(N + M)
+{-| Creating a union tree from two trees. Worst-case: O(N + M)
>>> union (fromList [5,3]) (fromList [5,7]) == fromList [3,5,7]
True
@@ -656,7 +656,7 @@ union t1 (Node _ _ l x r) = join (union l' l) x (union r' r)
where
(l',r') = split x t1
-{-| Creating a intersection tree from trees. O(N + N)
+{-| Creating a intersection tree from trees. Worst-case: O(N + N)
>>> intersection (fromList [5,3]) (fromList [5,7]) == singleton 5
True
@@ -671,7 +671,7 @@ intersection t1 (Node _ _ l x r)
where
(l',r') = split x t1
-{-| Creating a difference tree from trees. O(N + N)
+{-| Creating a difference tree from trees. Worst-case: O(N + N)
>>> difference (fromList [5,3]) (fromList [5,7]) == singleton 3
True
View
@@ -111,7 +111,7 @@ singleton x = Node B 1 Leaf x Leaf
----------------------------------------------------------------
-{-| Creating a tree from a list. O(N log N)
+{-| Creating a tree from a list. Worst-case: O(N log N)
>>> empty == fromList []
True
@@ -126,7 +126,7 @@ fromList = foldl' (flip insert) empty
----------------------------------------------------------------
-{-| Creating a list from a tree. O(N)
+{-| Creating a list from a tree. Worst-case: O(N)
>>> toList (fromList [5,3])
[3,5]
@@ -220,7 +220,7 @@ turnB' (Node _ h l x r) = Node B h l x r
----------------------------------------------------------------
-{-| Finding the minimum element. O(log N)
+{-| Finding the minimum element. Worst-case: O(log N)
>>> minimum (fromList [3,5,1])
1
@@ -233,7 +233,7 @@ minimum (Node _ _ Leaf x _) = x
minimum (Node _ _ l _ _) = minimum l
minimum _ = error "minimum"
-{-| Finding the maximum element. O(log N)
+{-| Finding the maximum element. Worst-case: O(log N)
>>> maximum (fromList [3,5,1])
5
@@ -282,7 +282,7 @@ valid t = isBalanced t && blackHeight t && isOrdered t
-- Chris Okasaki
--
-{-| Insertion. O(log N)
+{-| Insertion. Worst-case: O(log N)
>>> insert 5 (fromList [5,3]) == fromList [3,5]
True
@@ -359,7 +359,7 @@ unbalancedR _ _ _ _ _ = error "unbalancedR"
----------------------------------------------------------------
-{-| Deleting the minimum element. O(log N)
+{-| Deleting the minimum element. Worst-case: O(log N)
>>> deleteMin (fromList [5,3,7]) == fromList [5,7]
True
@@ -417,7 +417,7 @@ blackify :: RBTree a -> RBTreeBDel a
blackify s@(Node R _ _ _ _) = (turnB s, False)
blackify s = (s, True)
-{-| Deleting this element from a tree. O(log N)
+{-| Deleting this element from a tree. Worst-case: O(log N)
>>> delete 5 (fromList [5,3]) == singleton 3
True
@@ -451,7 +451,7 @@ delete' x (Node c h l y r) = case compare x y of
-- Set operations
----------------------------------------------------------------
-{-| Joining two trees with an element. O(log N)
+{-| Joining two trees with an element. Worst-case: O(log N)
Each element of the left tree must be less than the element.
Each element of the right tree must be greater than the element.
@@ -485,7 +485,7 @@ joinGT _ _ _ _ = error "joinGT"
----------------------------------------------------------------
-{-| Merging two trees. O(log N)
+{-| Merging two trees. Worst-case: O(log N)
Each element of the left tree must be less than each element of
the right tree. Both trees must have black root.
@@ -539,7 +539,7 @@ mergeEQ _ _ = error "mergeEQ"
----------------------------------------------------------------
-{-| Splitting a tree. O(log N)
+{-| Splitting a tree. Worst-case: O(log N)
>>> split 2 (fromList [5,3]) == (empty, fromList [3,5])
True
@@ -571,7 +571,7 @@ split kx (Node _ _ l x r) = case compare kx x of
----------------------------------------------------------------
-{-| Creating a union tree from two trees. O(N + M)
+{-| Creating a union tree from two trees. Worst-case: O(N + M)
>>> union (fromList [5,3]) (fromList [5,7]) == fromList [3,5,7]
True
@@ -584,7 +584,7 @@ union t1 (Node _ _ l x r) = join (union l' l) x (union r' r)
where
(l',r') = split x t1
-{-| Creating a intersection tree from trees. O(N + N)
+{-| Creating a intersection tree from trees. Worst-case: O(N + N)
>>> intersection (fromList [5,3]) (fromList [5,7]) == singleton 5
True
@@ -599,7 +599,7 @@ intersection t1 (Node _ _ l x r)
where
(l',r') = split x t1
-{-| Creating a difference tree from trees. O(N + N)
+{-| Creating a difference tree from trees. Worst-case: O(N + N)
>>> difference (fromList [5,3]) (fromList [5,7]) == singleton 3
True
View
@@ -116,7 +116,7 @@ singleton x = Node Leaf x Leaf
----------------------------------------------------------------
-{-| Insertion.
+{-| Insertion. Worst-case: O(N), amortized: O(log N).
prop> insert 5 (fromList [5,3]) == fromList [3,5]
prop> insert 7 (fromList [5,3]) == fromList [3,5,7]
@@ -182,7 +182,7 @@ member x t = case split x t of
----------------------------------------------------------------
-{-| Finding the minimum element.
+{-| Finding the minimum element. Worst-case: O(N), amortized: O(log N).
>>> fst $ Data.Set.Splay.minimum (fromList [3,5,1])
1
@@ -196,7 +196,7 @@ minimum :: Splay a -> (a, Splay a)
minimum Leaf = error "minimum"
minimum t = let (x,mt) = deleteMin t in (x, Node Leaf x mt)
-{-| Finding the maximum element.
+{-| Finding the maximum element. Worst-case: O(N), amortized: O(log N).
>>> fst $ Data.Set.Splay.maximum (fromList [3,5,1])
5
@@ -212,7 +212,7 @@ maximum t = let (x,mt) = deleteMax t in (x, Node mt x Leaf)
----------------------------------------------------------------
-{-| Deleting the minimum element.
+{-| Deleting the minimum element. Worst-case: O(N), amortized: O(log N).
>>> snd (deleteMin (fromList [5,3,7])) == fromList [5,7]
True
@@ -239,7 +239,7 @@ prop_deleteMinModel xs = ys == zs
ys = toList t'
zs = tail . L.nub . L.sort $ xs
-{-| Deleting the maximum
+{-| Deleting the maximum. Worst-case: O(N), amortized: O(log N).
>>> snd (deleteMax (fromList [(5,"a"), (3,"b"), (7,"c")])) == fromList [(3,"b"), (5,"a")]
True
@@ -311,7 +311,7 @@ prop_deleteModel xxs@(x:xs) = ys == zs
----------------------------------------------------------------
-{-| Creating a union set from two sets.
+{-| Creating a union set from two sets. Worst-case: O(N), amortized: O(log N).
>>> union (fromList [5,3]) (fromList [5,7]) == fromList [3,5,7]
True
Oops, something went wrong. Retry.

0 comments on commit 36f259e

Please sign in to comment.