Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
maxim-s committed Feb 16, 2017
1 parent 3efe1f3 commit d9e89f6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
4 changes: 0 additions & 4 deletions src/core/Akka.API.Tests/CoreAPISpec.ApproveCore.approved.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5145,10 +5145,6 @@ namespace Akka.Util.Internal.Collections
public T Next() { }
public System.Collections.Generic.IEnumerable<T> ToVector() { }
}
public class static ListExtensions
{
public static System.Collections.Generic.List<T> Shuffle<T>(this System.Collections.Generic.List<T> @this) { }
}
}
namespace Akka.Util.Reflection
{
Expand Down
5 changes: 4 additions & 1 deletion src/core/Akka.Cluster/ClusterDaemon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1863,7 +1863,10 @@ private void SendGossipRandom(int n)
if (!IsSingletonCluster && n > 0)
{
var localGossip = _latestGossip;
var possibleTargets = new List<UniqueAddress>(localGossip.Members.Where(m => ValidNodeForGossip(m.UniqueAddress)).Select(m => m.UniqueAddress));
var possibleTargets =
localGossip.Members.Where(m => ValidNodeForGossip(m.UniqueAddress))
.Select(m => m.UniqueAddress)
.ToList();
var randomTargets = possibleTargets.Count <= n ? possibleTargets : possibleTargets.Shuffle().Slice(0, n);
randomTargets.ForEach(GossipTo);
}
Expand Down
17 changes: 8 additions & 9 deletions src/core/Akka/Util/Internal/Collections/ListExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,19 @@

namespace Akka.Util.Internal.Collections
{
public static class ListExtensions
internal static class ListExtensions
{
public static List<T> Shuffle<T>(this List<T> @this)
{
var list = new List<T>(@this);
var rng = new Random();
var n = list.Count;
while (n > 1)
var r = ThreadLocalRandom.Current;
for (int i = list.Count - 1; i > 0; i--)
{
n--;
var k = rng.Next(n + 1);
var value = list[k];
list[k] = list[n];
list[n] = value;
int index = r.Next(i);
//swap
var tmp = list[index];
list[index] = list[i];
list[i] = tmp;
}
return list;
}
Expand Down

0 comments on commit d9e89f6

Please sign in to comment.