mercurial/worker.py
changeset 28181 f8efc8a3a991
parent 26587 56b2bcea2529
child 28292 3eb7faf6d958
equal deleted inserted replaced
28180:2836a43c7722 28181:f8efc8a3a991
   150 if os.name != 'nt':
   150 if os.name != 'nt':
   151     _platformworker = _posixworker
   151     _platformworker = _posixworker
   152     _exitstatus = _posixexitstatus
   152     _exitstatus = _posixexitstatus
   153 
   153 
   154 def partition(lst, nslices):
   154 def partition(lst, nslices):
   155     '''partition a list into N slices of equal size'''
   155     '''partition a list into N slices of roughly equal size
   156     n = len(lst)
   156 
   157     chunk, slop = n / nslices, n % nslices
   157     The current strategy takes every Nth element from the input. If
   158     end = 0
   158     we ever write workers that need to preserve grouping in input
   159     for i in xrange(nslices):
   159     we should consider allowing callers to specify a partition strategy.
   160         start = end
   160     '''
   161         end = start + chunk
   161     for i in range(nslices):
   162         if slop:
   162         yield lst[i::nslices]
   163             end += 1
       
   164             slop -= 1
       
   165         yield lst[start:end]