From 527b2982e250a37396bfa2ea0ec0403eb69d84cd Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Fri, 13 Oct 2017 10:19:27 +0200 Subject: [PATCH] Use maps instead of lists in why command --- src/Paket.Core/PackageAnalysis/Why.fs | 50 +++++++++++++-------------- src/Paket/Paket.fsproj | 4 +-- 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/src/Paket.Core/PackageAnalysis/Why.fs b/src/Paket.Core/PackageAnalysis/Why.fs index 603d16490d..b9e37e6a07 100644 --- a/src/Paket.Core/PackageAnalysis/Why.fs +++ b/src/Paket.Core/PackageAnalysis/Why.fs @@ -8,45 +8,43 @@ open Paket.Requirements open Chessie.ErrorHandling -type AdjLblGraph<'a, 'b> = list<'a * list<('a * 'b)>> +type AdjLblGraph<'a> = Map> -type LblPath<'a, 'b> = 'a * LblPathNode<'a, 'b> +type LblPath<'a> = PackageName * LblPathNode<'a> -and LblPathNode<'a, 'b> = -| LblPathNode of LblPath<'a, 'b> -| LblPathLeaf of 'a * 'b +and LblPathNode<'a> = +| LblPathNode of LblPath<'a> +| LblPathLeaf of PackageName * 'a module AdjLblGraph = - let adj n (g: AdjLblGraph<_, _>) = - g - |> List.find (fst >> (=) n) - |> snd - - let removeEdge ((n1,n2): 'a * 'a) (g: AdjLblGraph<'a, 'b>) = - g - |> List.map (fun (n, es) -> - if n1 <> n then - (n,es) - else - (n,es |> List.filter (fst >> ((<>)n2)))) - - let rec paths start stop g : list> = - [ for (n, lbl) in adj start g do + let inline adj n (g: AdjLblGraph<_>) = + Map.find n g + + let inline removeEdge (n1,n2) (g: AdjLblGraph<'b>) = + match Map.tryFind n1 g with + | None -> g + | Some v -> + let v' = v |> Map.remove n2 + Map.add n1 v' g + + let rec paths start stop g : list> = + [ for kv in adj start g do + let n, lbl = kv.Key, kv.Value if n = stop then yield (start, LblPathLeaf (stop, lbl)) for path in paths n stop (removeEdge (start,n) g) do yield (start, LblPathNode path)] -let depGraph (res : PackageResolver.PackageResolution) : AdjLblGraph<_,_> = +let depGraph (res : PackageResolver.PackageResolution) : AdjLblGraph<_> = res - |> Seq.toList - |> List.map (fun pair -> pair.Key, (pair.Value.Dependencies - |> Set.map (fun (p,v,f) -> p,(v,f)) - |> Set.toList)) + |> Seq.map (fun pair -> pair.Key, (pair.Value.Dependencies + |> Seq.map (fun (p,v,f) -> p,(v,f)) + |> Map.ofSeq)) + |> Map.ofSeq type WhyOptions = { Details : bool } -type DependencyChain = LblPath +type DependencyChain = LblPath [] module DependencyChain = diff --git a/src/Paket/Paket.fsproj b/src/Paket/Paket.fsproj index 4958001c23..ea154f70e0 100644 --- a/src/Paket/Paket.fsproj +++ b/src/Paket/Paket.fsproj @@ -33,9 +33,9 @@ Project install C:\temp\Gu.Reactive - update + why ncrontab C:\proj\Paket - D:\temp\test + D:\code\bookstore\ true