Flush (work in progress)
[mono.git] / mcs / class / corlib / System.Collections.Concurrent / Partitioner.cs
1 // 
2 // Partitioner.cs
3 //  
4 // Author:
5 //       Jérémie "Garuma" Laval <jeremie.laval@gmail.com>
6 // 
7 // Copyright (c) 2009 Jérémie "Garuma" Laval
8 // 
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:
15 // 
16 // The above copyright notice and this permission notice shall be included in
17 // all copies or substantial portions of the Software.
18 // 
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
25 // THE SOFTWARE.
26
27 using System;
28 using System.Collections.Generic;
29
30 #if NET_4_0 || BOOTSTRAP_NET_4_0
31
32 namespace System.Collections.Concurrent
33 {
34         public static class Partitioner
35         {
36                 public static OrderablePartitioner<TSource> Create<TSource> (IEnumerable<TSource> source)
37                 {
38                         IList<TSource> tempIList = source as IList<TSource>;
39                         if (tempIList != null)
40                                 return Create (tempIList, true);
41                         
42                         return new EnumerablePartitioner<TSource> (source);
43                 }
44                 
45                 public static OrderablePartitioner<TSource> Create<TSource> (TSource[] source, bool loadBalance)
46                 {
47                         return Create ((IList<TSource>)source, loadBalance);
48                 }
49                 
50                 public static OrderablePartitioner<TSource> Create<TSource> (IList<TSource> source, bool loadBalance)
51                 {
52                         return new ListPartitioner<TSource> (source);
53                 }
54                 
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,
57                                                                              int toExclusive)
58                 {
59                         return Create (fromInclusive, toExclusive, 1);
60                 }
61                 
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,
64                                                                              int toExclusive,
65                                                                              int rangeSize)
66                 {
67                         throw new NotImplementedException ();
68                 }
69                 
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,
72                                                                                long toExclusive)
73                 {
74                         return Create (fromInclusive, toExclusive, 1);
75                 }
76                 
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,
79                                                                                long toExclusive,
80                                                                                long rangeSize)
81                 {
82                         throw new NotImplementedException ();
83                 }
84         }
85         
86         public abstract class Partitioner<TSource>
87         {
88                 protected Partitioner ()
89                 {
90                         
91                 }
92                 
93                 public virtual IEnumerable<TSource> GetDynamicPartitions ()
94                 {
95                         if (!SupportsDynamicPartitions)
96                                 throw new NotSupportedException ();
97                         
98                         return null;
99                 }
100                 
101                 public abstract IList<IEnumerator<TSource>> GetPartitions (int partitionCount);
102                 
103                 public virtual bool SupportsDynamicPartitions {
104                         get {
105                                 return false;
106                         }
107                 }
108         }
109 }
110 #endif