Move towards displaying tree links in inventory

This commit is contained in:
2024-09-13 12:02:28 +01:00
parent c81fd5490d
commit bd681a577c
8 changed files with 85 additions and 45 deletions
+13
View File
@@ -1,6 +1,7 @@
module Dodge.DoubleTree where
import Dodge.Data.DoubleTree
import qualified Data.IntMap.Strict as IM
ldtToDT :: LabelDoubleTree b a -> DoubleTree a
ldtToDT (LDT x l r) = DT x (map (ldtToDT . snd) l) (map (ldtToDT . snd) r)
@@ -18,6 +19,18 @@ dtIL nt (DT x l r) = map doindent (concat (headMap (dtIL DTBottomNode) (dtIL DTM
where
doindent (a,b,c) = (a,b+1,c)
dtToAdjacency :: (a -> Int) -> DoubleTree a -> IM.IntMap [Int]
dtToAdjacency f (DT x l r) = IM.insert (f x) (map g l <> map g r)
. IM.unions $ map (dtToAdjacency f) $ l <> r
where
g = f . _dtValue
dtToUpDownAdj :: (a -> Int) -> DoubleTree a -> IM.IntMap ([Int],[Int])
dtToUpDownAdj f (DT x l r) = IM.insert (f x) (map g l , map g r)
. IM.unions $ map (dtToUpDownAdj f) $ l <> r
where
g = f . _dtValue
ldtToIndentList :: LabelDoubleTree b a -> [(a,Int,LabelDoubleTreeNodeType b)]
ldtToIndentList = ldtIL LDTRootNode