Skip to content

Commit

Permalink
Use maps instead of lists in why command
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Oct 13, 2017
1 parent b3cfec7 commit 527b298
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 28 deletions.
50 changes: 24 additions & 26 deletions src/Paket.Core/PackageAnalysis/Why.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,43 @@ open Paket.Requirements

open Chessie.ErrorHandling

type AdjLblGraph<'a, 'b> = list<'a * list<('a * 'b)>>
type AdjLblGraph<'a> = Map<PackageName , Map<PackageName, 'a>>

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<LblPath<_, _>> =
[ 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<LblPath<_>> =
[ 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<PackageName, (VersionRequirement * FrameworkRestrictions)>
type DependencyChain = LblPath<VersionRequirement * FrameworkRestrictions>

[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
module DependencyChain =
Expand Down
4 changes: 2 additions & 2 deletions src/Paket/Paket.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
<StartAction>Project</StartAction>
<StartArguments>install</StartArguments>
<StartWorkingDirectory>C:\temp\Gu.Reactive</StartWorkingDirectory>
<StartArguments>update</StartArguments>
<StartArguments>why ncrontab</StartArguments>
<StartWorkingDirectory>C:\proj\Paket</StartWorkingDirectory>
<StartWorkingDirectory>D:\temp\test</StartWorkingDirectory>
<StartWorkingDirectory>D:\code\bookstore\</StartWorkingDirectory>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<Optimize>true</Optimize>
Expand Down

0 comments on commit 527b298

Please sign in to comment.