5 // Jérémie "Garuma" Laval <jeremie.laval@gmail.com>
7 // Copyright (c) 2009 Jérémie "Garuma" Laval
9 // Permission is hereby granted, free of charge, to any person obtaining a copy
10 // of this software and associated documentation files (the "Software"), to deal
11 // in the Software without restriction, including without limitation the rights
12 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 // copies of the Software, and to permit persons to whom the Software is
14 // furnished to do so, subject to the following conditions:
16 // The above copyright notice and this permission notice shall be included in
17 // all copies or substantial portions of the Software.
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28 using System.Collections.Generic;
30 #if NET_4_0 || BOOTSTRAP_NET_4_0
32 namespace System.Collections.Concurrent
34 public static class Partitioner
36 public static OrderablePartitioner<TSource> Create<TSource> (IEnumerable<TSource> source)
38 IList<TSource> tempIList = source as IList<TSource>;
39 if (tempIList != null)
40 return Create (tempIList, true);
42 return new EnumerablePartitioner<TSource> (source);
45 public static OrderablePartitioner<TSource> Create<TSource> (TSource[] source, bool loadBalance)
47 return Create ((IList<TSource>)source, loadBalance);
50 public static OrderablePartitioner<TSource> Create<TSource> (IList<TSource> source, bool loadBalance)
52 return new ListPartitioner<TSource> (source);
55 [MonoTODO("What range size is supposed to be in context and what the result returned looks like")]
56 public static OrderablePartitioner<Tuple<int, int>> Create (int fromInclusive,
59 return Create (fromInclusive, toExclusive, 1);
62 [MonoTODO("What range size is supposed to be in context and what the result returned looks like")]
63 public static OrderablePartitioner<Tuple<int, int>> Create (int fromInclusive,
67 throw new NotImplementedException ();
70 [MonoTODO("What range size is supposed to be in context and what the result returned looks like")]
71 public static OrderablePartitioner<Tuple<long, long>> Create (long fromInclusive,
74 return Create (fromInclusive, toExclusive, 1);
77 [MonoTODO("What range size is supposed to be in context and what the result returned looks like")]
78 public static OrderablePartitioner<Tuple<long, long>> Create (long fromInclusive,
82 throw new NotImplementedException ();
86 public abstract class Partitioner<TSource>
88 protected Partitioner ()
93 public virtual IEnumerable<TSource> GetDynamicPartitions ()
95 if (!SupportsDynamicPartitions)
96 throw new NotSupportedException ();
101 public abstract IList<IEnumerator<TSource>> GetPartitions (int partitionCount);
103 public virtual bool SupportsDynamicPartitions {