Skip to content

Commit 6a05325

Browse files
authored
Merge pull request #35 from matiii/feature/i20-page-rank
i20 omit one loop
2 parents 3c0dbce + 5d72b2e commit 6a05325

File tree

2 files changed

+4
-9
lines changed

2 files changed

+4
-9
lines changed

src/Dijkstra.NET/Dijkstra.NET.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22

33
<PropertyGroup>
44
<TargetFrameworks>netstandard1.3;net40</TargetFrameworks>
5-
<Version>1.2.0</Version>
5+
<Version>1.2.1</Version>
66
<Authors>Mateusz Mazurek</Authors>
77
<Company />
88
<Description>Graph processing library.</Description>
9-
<PackageLicenseUrl>https://github.com/matiii/Dijkstra.NET/blob/master/LICENSE</PackageLicenseUrl>
109
<PackageProjectUrl>https://github.com/matiii/Dijkstra.NET</PackageProjectUrl>
1110
<RepositoryUrl>https://github.com/matiii/Dijkstra.NET</RepositoryUrl>
1211
<PackageTags>graphs graph-theory dijkstra page-rank</PackageTags>

src/Dijkstra.NET/PageRank/PageRankExtensions.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,13 @@ public static PageRankResult CalculatePageRank(this IPageRankGraph graph, double
1515
{
1616
var pageRank = new Dictionary<uint, double>();
1717
var pageRankNext = new Dictionary<uint, double>();
18-
19-
// 0
20-
foreach (var node in graph)
21-
{
22-
pageRank[node.Key] = 1.0 / graph.NodesCount;
23-
}
2418

19+
double initPr = 1.0 / graph.NodesCount;
20+
2521
// 1
2622
foreach (var node in graph)
2723
{
28-
pageRankNext[node.Key] = (1 - d) / graph.NodesCount + d * node.Parents.Sum(x => pageRank[x.Key] / x.NumberOfEdges);
24+
pageRankNext[node.Key] = (1 - d) / graph.NodesCount + d * node.Parents.Sum(x => initPr / x.NumberOfEdges);
2925
}
3026

3127
// 2

0 commit comments

Comments
 (0)