X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2Fcorlib%2FSystem.Collections.Concurrent%2FPartitioner.cs;h=92b5665712cfbf2eea2fd2db9d956672ecd3d4ee;hb=5b558abeeb255a3179d4ca6a85617e051c6abd38;hp=24987ae73bc058ad7c15a32bc6e1165a3df1a0b7;hpb=e531fc2677409bbcd1069011d05805e5f2296db3;p=mono.git diff --git a/mcs/class/corlib/System.Collections.Concurrent/Partitioner.cs b/mcs/class/corlib/System.Collections.Concurrent/Partitioner.cs index 24987ae73bc..92b5665712c 100644 --- a/mcs/class/corlib/System.Collections.Concurrent/Partitioner.cs +++ b/mcs/class/corlib/System.Collections.Concurrent/Partitioner.cs @@ -1,4 +1,3 @@ -#if NET_4_0 // // Partitioner.cs // @@ -25,11 +24,15 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +#if NET_4_0 + using System; using System.Collections.Generic; namespace System.Collections.Concurrent { + using Partitioners; + public static class Partitioner { public static OrderablePartitioner Create (IEnumerable source) @@ -41,44 +44,59 @@ namespace System.Collections.Concurrent return new EnumerablePartitioner (source); } - public static OrderablePartitioner Create (TSource[] source, bool loadBalance) + public static OrderablePartitioner Create (TSource[] array, bool loadBalance) { - return Create ((IList)source, loadBalance); + return Create ((IList)array, loadBalance); } - public static OrderablePartitioner Create (IList source, bool loadBalance) + public static OrderablePartitioner Create (IList list, bool loadBalance) { - return new ListPartitioner (source); + return new ListPartitioner (list); } - [MonoTODO("What range size is supposed to be in context and what the result returned looks like")] public static OrderablePartitioner> Create (int fromInclusive, - int toExclusive) + int toExclusive) { - return Create (fromInclusive, toExclusive, 1); + // This formula that is somewhat non-straighforward was guessed based on MS output + int rangeSize = (toExclusive - fromInclusive) / (Environment.ProcessorCount * 3); + if (rangeSize < 1) + rangeSize = 1; + + return Create (fromInclusive, toExclusive, rangeSize); } - - [MonoTODO("What range size is supposed to be in context and what the result returned looks like")] + public static OrderablePartitioner> Create (int fromInclusive, - int toExclusive, - int rangeSize) + int toExclusive, + int rangeSize) { - throw new NotImplementedException (); + if (fromInclusive >= toExclusive) + throw new ArgumentOutOfRangeException ("toExclusive"); + if (rangeSize <= 0) + throw new ArgumentOutOfRangeException ("rangeSize"); + + return new UserRangePartitioner (fromInclusive, toExclusive, rangeSize); } - - [MonoTODO("What range size is supposed to be in context and what the result returned looks like")] + public static OrderablePartitioner> Create (long fromInclusive, - long toExclusive) + long toExclusive) { - return Create (fromInclusive, toExclusive, 1); + long rangeSize = (toExclusive - fromInclusive) / (Environment.ProcessorCount * 3); + if (rangeSize < 1) + rangeSize = 1; + + return Create (fromInclusive, toExclusive, rangeSize); } - - [MonoTODO("What range size is supposed to be in context and what the result returned looks like")] + public static OrderablePartitioner> Create (long fromInclusive, - long toExclusive, - long rangeSize) + long toExclusive, + long rangeSize) { - throw new NotImplementedException (); + if (rangeSize <= 0) + throw new ArgumentOutOfRangeException ("rangeSize"); + if (fromInclusive >= toExclusive) + throw new ArgumentOutOfRangeException ("toExclusive"); + + return new UserLongRangePartitioner (fromInclusive, toExclusive, rangeSize); } }