Show More
@@ -59,17 +59,19 b' else:' | |||
|
59 | 59 | class Map(object): |
|
60 | 60 | """A class for partitioning a sequence using a map.""" |
|
61 | 61 | |
|
62 | def getPartition(self, seq, p, q): | |
|
63 |
"""Returns the pth partition of q partitions of seq. |
|
|
62 | def getPartition(self, seq, p, q, n=None): | |
|
63 | """Returns the pth partition of q partitions of seq. | |
|
64 | 64 |
|
|
65 | The length can be specified as `n`, | |
|
66 | otherwise it is the value of `len(seq)` | |
|
67 | """ | |
|
68 | n = len(seq) if n is None else n | |
|
65 | 69 | # Test for error conditions here |
|
66 | 70 | if p<0 or p>=q: |
|
67 | print "No partition exists." | |
|
68 | return | |
|
71 | raise ValueError("must have 0 <= p <= q, but have p=%s,q=%s" % (p, q)) | |
|
69 | 72 | |
|
70 | N = len(seq) | |
|
71 |
|
|
|
72 | basesize = N // q | |
|
73 | remainder = n % q | |
|
74 | basesize = n // q | |
|
73 | 75 | |
|
74 | 76 | if p < remainder: |
|
75 | 77 | low = p * (basesize + 1) |
@@ -104,19 +106,14 b' class Map(object):' | |||
|
104 | 106 | return listOfPartitions |
|
105 | 107 | |
|
106 | 108 | class RoundRobinMap(Map): |
|
107 | """Partitions a sequence in a roun robin fashion. | |
|
109 | """Partitions a sequence in a round robin fashion. | |
|
108 | 110 | |
|
109 | 111 | This currently does not work! |
|
110 | 112 | """ |
|
111 | 113 | |
|
112 | def getPartition(self, seq, p, q): | |
|
113 | # if not isinstance(seq,(list,tuple)): | |
|
114 | # raise NotImplementedError("cannot RR partition type %s"%type(seq)) | |
|
115 | return seq[p:len(seq):q] | |
|
116 | #result = [] | |
|
117 | #for i in range(p,len(seq),q): | |
|
118 | # result.append(seq[i]) | |
|
119 | #return result | |
|
114 | def getPartition(self, seq, p, q, n=None): | |
|
115 | n = len(seq) if n is None else n | |
|
116 | return seq[p:n:q] | |
|
120 | 117 | |
|
121 | 118 | def joinPartitions(self, listOfPartitions): |
|
122 | 119 | testObject = listOfPartitions[0] |
General Comments 0
You need to be logged in to leave comments.
Login now