Core/Refactor: Part 3
This commit is contained in:
@@ -66,6 +66,9 @@ namespace System.Collections.Generic
|
||||
}
|
||||
public static KeyValuePair<TKey, TValue> Find<TKey, TValue>(this IDictionary<TKey, TValue> dict, TKey key)
|
||||
{
|
||||
if (!dict.ContainsKey(key))
|
||||
return default(KeyValuePair<TKey, TValue>);
|
||||
|
||||
return new KeyValuePair<TKey, TValue>(key, dict[key]);
|
||||
}
|
||||
|
||||
@@ -113,17 +116,17 @@ namespace System.Collections.Generic
|
||||
}
|
||||
}
|
||||
|
||||
public static void RandomResize<T>(this ICollection<T> list, Predicate<T> predicate, uint size)
|
||||
public static void RandomResize<T>(this List<T> list, Predicate<T> predicate, uint size)
|
||||
{
|
||||
List<T> listCopy = new List<T>();
|
||||
foreach (var obj in list)
|
||||
if (predicate(obj))
|
||||
listCopy.Add(obj);
|
||||
for (var i = 0; i < list.Count; ++i)
|
||||
{
|
||||
var obj = list[i];
|
||||
if (!predicate(obj))
|
||||
list.Remove(obj);
|
||||
}
|
||||
|
||||
if (size != 0)
|
||||
listCopy.Resize(size);
|
||||
|
||||
list = listCopy;
|
||||
list.Resize(size);
|
||||
}
|
||||
|
||||
public static T SelectRandom<T>(this IEnumerable<T> source)
|
||||
|
||||
@@ -72,7 +72,7 @@ namespace System
|
||||
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
int randValue = -1;
|
||||
int randValue;
|
||||
|
||||
do
|
||||
{
|
||||
@@ -128,7 +128,7 @@ namespace System
|
||||
|
||||
public static BigInteger ToBigInteger<T>(this T value, bool isBigEndian = false)
|
||||
{
|
||||
var ret = BigInteger.Zero;
|
||||
BigInteger ret;
|
||||
|
||||
switch (typeof(T).Name)
|
||||
{
|
||||
|
||||
@@ -100,9 +100,9 @@ public class RandomHelper
|
||||
|
||||
public static T RAND<T>(params T[] args)
|
||||
{
|
||||
int rand = IRand(0, args.Length - 1);
|
||||
int randIndex = IRand(0, args.Length - 1);
|
||||
|
||||
return args[rand];
|
||||
return args[randIndex];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user