mirror of
https://github.com/simonmichael/hledger.git
synced 2024-12-27 12:24:43 +03:00
pkg!: Remove Hledger.Utils.Tree module.
This very small module was only used in Hledger.Data.Account, so the code was moved into that module instead.
This commit is contained in:
parent
1ed06f3bc8
commit
f1994d5aa8
@ -13,18 +13,16 @@ module Hledger.Data.Account
|
||||
where
|
||||
import qualified Data.HashSet as HS
|
||||
import qualified Data.HashMap.Strict as HM
|
||||
import Data.List (find, sortOn)
|
||||
import Data.List (find, foldl', sortOn)
|
||||
import Data.List.Extra (groupOn)
|
||||
import qualified Data.Map as M
|
||||
import Data.Ord (Down(..))
|
||||
import Safe (headMay)
|
||||
import Text.Printf
|
||||
import Text.Printf (printf)
|
||||
|
||||
import Hledger.Data.AccountName
|
||||
import Hledger.Data.AccountName (expandAccountName, clipOrEllipsifyAccountName)
|
||||
import Hledger.Data.Amount
|
||||
import Hledger.Data.Posting ()
|
||||
import Hledger.Data.Types
|
||||
import Hledger.Utils
|
||||
|
||||
|
||||
-- deriving instance Show Account
|
||||
@ -91,6 +89,22 @@ accountTree rootname as = nullacct{aname=rootname, asubs=map (uncurry accountTre
|
||||
,asubs=map (uncurry accountTree') $ M.assocs m
|
||||
}
|
||||
|
||||
-- | An efficient-to-build tree suggested by Cale Gibbard, probably
|
||||
-- better than accountNameTreeFrom.
|
||||
newtype FastTree a = T (M.Map a (FastTree a))
|
||||
deriving (Show, Eq, Ord)
|
||||
|
||||
mergeTrees :: (Ord a) => FastTree a -> FastTree a -> FastTree a
|
||||
mergeTrees (T m) (T m') = T (M.unionWith mergeTrees m m')
|
||||
|
||||
treeFromPath :: [a] -> FastTree a
|
||||
treeFromPath [] = T M.empty
|
||||
treeFromPath (x:xs) = T (M.singleton x (treeFromPath xs))
|
||||
|
||||
treeFromPaths :: (Ord a) => [[a]] -> FastTree a
|
||||
treeFromPaths = foldl' mergeTrees (T M.empty) . map treeFromPath
|
||||
|
||||
|
||||
-- | Tie the knot so all subaccounts' parents are set correctly.
|
||||
tieAccountParents :: Account -> Account
|
||||
tieAccountParents = tie Nothing
|
||||
|
@ -4,7 +4,7 @@ Standard imports and utilities which are useful everywhere, or needed low
|
||||
in the module hierarchy. This is the bottom of hledger's module graph.
|
||||
|
||||
-}
|
||||
{-# LANGUAGE LambdaCase #-}
|
||||
{-# LANGUAGE LambdaCase #-}
|
||||
|
||||
module Hledger.Utils (---- provide these frequently used modules - or not, for clearer api:
|
||||
-- module Control.Monad,
|
||||
@ -25,7 +25,6 @@ module Hledger.Utils (---- provide these frequently used modules - or not, for c
|
||||
module Hledger.Utils.Text,
|
||||
module Hledger.Utils.Test,
|
||||
module Hledger.Utils.Color,
|
||||
module Hledger.Utils.Tree,
|
||||
-- Debug.Trace.trace,
|
||||
-- module Data.PPrint,
|
||||
-- the rest need to be done in each module I think
|
||||
@ -60,7 +59,6 @@ import Hledger.Utils.String
|
||||
import Hledger.Utils.Text
|
||||
import Hledger.Utils.Test
|
||||
import Hledger.Utils.Color
|
||||
import Hledger.Utils.Tree
|
||||
|
||||
|
||||
-- tuples
|
||||
|
@ -1,26 +0,0 @@
|
||||
module Hledger.Utils.Tree
|
||||
( FastTree(..)
|
||||
, treeFromPaths
|
||||
) where
|
||||
|
||||
-- import Data.Char
|
||||
import Data.List (foldl')
|
||||
import qualified Data.Map as M
|
||||
|
||||
-- | An efficient-to-build tree suggested by Cale Gibbard, probably
|
||||
-- better than accountNameTreeFrom.
|
||||
newtype FastTree a = T (M.Map a (FastTree a))
|
||||
deriving (Show, Eq, Ord)
|
||||
|
||||
emptyTree :: FastTree a
|
||||
emptyTree = T M.empty
|
||||
|
||||
mergeTrees :: (Ord a) => FastTree a -> FastTree a -> FastTree a
|
||||
mergeTrees (T m) (T m') = T (M.unionWith mergeTrees m m')
|
||||
|
||||
treeFromPath :: [a] -> FastTree a
|
||||
treeFromPath [] = T M.empty
|
||||
treeFromPath (x:xs) = T (M.singleton x (treeFromPath xs))
|
||||
|
||||
treeFromPaths :: (Ord a) => [[a]] -> FastTree a
|
||||
treeFromPaths = foldl' mergeTrees emptyTree . map treeFromPath
|
@ -85,7 +85,6 @@ library
|
||||
Hledger.Utils.String
|
||||
Hledger.Utils.Test
|
||||
Hledger.Utils.Text
|
||||
Hledger.Utils.Tree
|
||||
Text.Tabular.AsciiWide
|
||||
other-modules:
|
||||
Text.Megaparsec.Custom
|
||||
|
@ -137,7 +137,6 @@ library:
|
||||
- Hledger.Utils.String
|
||||
- Hledger.Utils.Test
|
||||
- Hledger.Utils.Text
|
||||
- Hledger.Utils.Tree
|
||||
- Text.Tabular.AsciiWide
|
||||
# other-modules:
|
||||
# - Ledger.Parser.Text
|
||||
|
Loading…
Reference in New Issue
Block a user