packages feed

twentefp-trees 0.1.0.0 → 0.1.0.1

raw patch · 2 files changed

+85/−2 lines, 2 filesPVP: minor bump suggested

API additions: PVP suggests at least a minor version bump

API changes (from Hackage documentation)

+ FPPrac.Trees.RedBlackTree: BlackG :: ColorG
+ FPPrac.Trees.RedBlackTree: GreyG :: ColorG
+ FPPrac.Trees.RedBlackTree: RBNodeG :: ColorG -> String -> [RBTreeG] -> RBTreeG
+ FPPrac.Trees.RedBlackTree: RedG :: ColorG
+ FPPrac.Trees.RedBlackTree: data ColorG
+ FPPrac.Trees.RedBlackTree: data RBTreeG
+ FPPrac.Trees.RedBlackTree: exampleTree :: RBTreeG
+ FPPrac.Trees.RedBlackTree: instance GeneralizeTree RBTreeG
+ FPPrac.Trees.RedBlackTree: showRBTree :: RBTreeG -> IO ()
+ FPPrac.Trees.RedBlackTree: showRBTreeList :: [RBTreeG] -> IO ()

Files

+ src/FPPrac/Trees/RedBlackTree.hs view
@@ -0,0 +1,82 @@+module FPPrac.Trees.RedBlackTree
+        ( showRBTree
+        , showRBTreeList
+        , RBTreeG(..)
+        , ColorG(..)
+        , exampleTree
+        )where
+
+import FPPrac.Trees.GeneralTree
+import FPPrac.Trees.LayoutTree
+import EventLoop.Output
+
+data ColorG = RedG
+            | BlackG
+            | GreyG
+
+data RBTreeG = RBNodeG ColorG String [RBTreeG]
+  
+instance GeneralizeTree RBTreeG where
+    generalizeTree (RBNodeG col _ [])       = GeneralTreeBox content []
+                                            where
+                                                content = [GeneralNode (colorGToColor col) 5]
+                                                
+    generalizeTree (RBNodeG col str children) = GeneralTreeBox content children'WithLines
+                                            where
+                                                content = [GeneralNode (colorGToColor col) 20, GeneralNodeText (0,0,0) str]
+                                                children' = map generalizeTree children
+                                                line = GeneralLine (0,0,0)
+                                                children'WithLines = zip (repeat line) children'
+
+colorGToColor :: ColorG -> Color
+colorGToColor RedG   = (255, 0, 0)
+colorGToColor BlackG = (0, 0, 0)
+colorGToColor GreyG  = (125, 125, 125)
+                                                
+showRBTree :: RBTreeG -> IO ()
+showRBTree rbTree = showRBTreeList [rbTree]
+
+showRBTreeList :: [RBTreeG] -> IO ()                                                
+showRBTreeList rbTrees = outSingle (OutGraphical (Draw (showRBTreeList' 0 0 rbTrees) "trees"))
+
+showRBTreeList' :: TopOffset -> Int -> [RBTreeG] -> GObject
+showRBTreeList' _ _ [] = Container []
+showRBTreeList' top i (rbTree:ts) = Container (text:pGeneral:gts)
+                                where
+                                (Container gts) = showRBTreeList' top' i' ts
+                                top' = 10 + bottomGeneral --(max bottomGeneral bottomRB)
+                                (lGeneral, rightGeneral, bottomGeneral) = layoutGeneralTree 0 top (generalizeTree rbTree)
+                                --(lRB, _, bottomRB)                = layoutRBTree (rightGeneral + 30) top rbTree
+                                pGeneral = printTree lGeneral
+                                --pRB      = printTree lRB
+                                i' = i + 1
+                                text = treeIndex i (0, top)
+
+layoutRBTree :: LeftOffset -> TopOffset -> RBTreeG -> (LayoutTree, RightOffset, BottomOffset)
+layoutRBTree left top rbTree = layoutGeneralTree left top $ generalizeTree rbTree               
+               
+               
+exampleTree = RBNodeG BlackG "12"
+                        [ RBNodeG RedG "11"
+                                    [ RBNodeG BlackG "16"
+                                                [ RBNodeG BlackG "" [],
+                                                  RBNodeG BlackG "" []
+                                                ],
+                                      RBNodeG BlackG "24"
+                                                [RBNodeG BlackG "" [],
+                                                 RBNodeG BlackG "" []
+                                                ]
+                                    ],
+                          RBNodeG RedG "13"
+                                    [RBNodeG BlackG "36" [],
+                                     RBNodeG BlackG "28"
+                                               [RBNodeG RedG "36"
+                                                          [RBNodeG BlackG "" [],
+                                                           RBNodeG BlackG "" []
+                                                          ],
+                                                RBNodeG BlackG "" []
+                                               ]
+                                    ]
+                        ]          
+
+                                                
twentefp-trees.cabal view
@@ -1,5 +1,5 @@ name:                twentefp-trees
-version:             0.1.0.0
+version:             0.1.0.1
 synopsis:            Tree type and show functions for lab assignment of University of Twente. Contains RoseTree and ParseTree      
 license:             BSD3
 license-file:        LICENSE
@@ -10,7 +10,8 @@ 
 library
   exposed-modules:     FPPrac.Trees.RoseTree,
-                       FPPrac.Trees.ParseTree
+                       FPPrac.Trees.ParseTree,
+                       FPPrac.Trees.RedBlackTree
   Other-modules: 
         FPPrac.Trees.LayoutTree,
         FPPrac.Trees.GeneralTree