summaryrefslogtreecommitdiff
path: root/src/Erebos/Storage/Graph.hs
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2026-09-10 20:06:59 +0200
committerRoman Smrž <roman.smrz@seznam.cz>2026-09-10 20:06:59 +0200
commit571949997bf0282370640b464532d5ec9a16f47b (patch)
treeeee0c0d6e97bc05c3798d75b4fc328a17beacc5d /src/Erebos/Storage/Graph.hs
parent50e3f4e0cc313828aa6682ebd270e2abbfef422a (diff)
Improve filterAncestors to avoid walk to rootHEADmaster
Diffstat (limited to 'src/Erebos/Storage/Graph.hs')
-rw-r--r--src/Erebos/Storage/Graph.hs17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/Erebos/Storage/Graph.hs b/src/Erebos/Storage/Graph.hs
index 99ad3e6..853143f 100644
--- a/src/Erebos/Storage/Graph.hs
+++ b/src/Erebos/Storage/Graph.hs
@@ -127,12 +127,17 @@ precedesOrEquals x y = filterAncestors [ x, y ] == [ y ]
filterAncestors :: Storable a => [ Stored a ] -> StoredTips a
filterAncestors [ x ] = [ x ]
filterAncestors xs = let xs' = uniq $ sort xs
- in helper xs' xs'
- where helper remains walk = case generationMax walk of
- Just x -> let px = previous x
- remains' = filter (\r -> all (/=r) px) remains
- in helper remains' $ uniq $ sort (px ++ filter (/=x) walk)
- Nothing -> remains
+ in sort $ helper xs' xs'
+ where
+ helper [] _ = []
+ helper remains walk =
+ case generationMax walk of
+ Just x ->
+ let px = previous x
+ youngerThenX r = Just GT == compareGeneration (storedGeneration r) (storedGeneration x)
+ ( returned, remains' ) = partition youngerThenX $ filter (\r -> all (/= r) px) remains
+ in returned ++ helper remains' (uniq $ sort (px ++ filter (/= x) walk))
+ Nothing -> remains
commonAncestors :: Storable a => [ Stored a ] -> [ Stored a ] -> StoredTips a
commonAncestors [] _ = []