Skip to content

Commit

Permalink
Update ParallelAlgoKruskal.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyKuz1001 authored Dec 8, 2019
1 parent 26ef6b4 commit 751cc47
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions Task02/ParallelAlgoKruskal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace Task02
{
public class ParallelAlgoKruskal
{
static Random rand = new Random();
static int[] dsu;
static int parallelDepth = 3; // глубина рекурсии, до которой происходит распараллеливание сортировки рёбер

Expand All @@ -19,7 +20,7 @@ static bool unionDsu(int x, int y)
y = getDsu(y);
if (x == y)
return false;
if ((x + 2 * y) % 4 * 2 % 6 != 0) // псевдорандом
if (rand.Next(0, 1) == 1) // псевдорандом
dsu[y] = x;
else
dsu[x] = y;
Expand Down Expand Up @@ -48,26 +49,16 @@ static void parallelSort<T>(T[] edges, T[] buffer, int LIndex, int RIndex, int p
int i = LIndex, j = MIndex;
for (int k = LIndex; k < RIndex; k++)
{
if (i == MIndex)
if (i == MIndex || (j != RIndex && edges[i].CompareTo(edges[j]) >= 0))
{
buffer[k] = edges[j];
j++;
}
else if (j == RIndex)
{
buffer[k] = edges[i];
i++;
}
else if (edges[i].CompareTo(edges[j]) < 0)
else
{
buffer[k] = edges[i];
i++;
}
else
{
buffer[k] = edges[j];
j++;
}
}
for (int k = LIndex; k < RIndex; k++)
edges[k] = buffer[k];
Expand Down

0 comments on commit 751cc47

Please sign in to comment.