Mercurial > repos > yufei-luo > s_mart
view commons/core/launcher/LauncherUtils.py @ 6:769e306b7933
Change the repository level.
author | yufei-luo |
---|---|
date | Fri, 18 Jan 2013 04:54:14 -0500 |
parents | |
children | 94ab73e8a190 |
line wrap: on
line source
class LauncherUtils(object): @staticmethod def createHomogeneousSizeList(lStringSizeTuples, maxSize): lStringSizeTuplesSorted = sorted(lStringSizeTuples, key=lambda stringSizeTuple:(stringSizeTuple[1], stringSizeTuple[0]), reverse = True) lStringSizeList = [] lStringSize = [] sumTupleSize = 0 iteratorFromBegin = 0 iteratorFromEnd = len(lStringSizeTuplesSorted) - 1 for tuple in lStringSizeTuplesSorted: if sumTupleSize + tuple[1] < maxSize: lStringSize.append(tuple[0]) sumTupleSize += tuple[1] elif tuple[1] >= maxSize: lStringSizeList.append([tuple[0]]) else: tupleFromEnd = lStringSizeTuplesSorted[iteratorFromEnd] while sumTupleSize + tupleFromEnd[1] < maxSize and iteratorFromBegin < iteratorFromEnd: lStringSize.append(tupleFromEnd[0]) sumTupleSize += tupleFromEnd[1] del lStringSizeTuplesSorted[iteratorFromEnd] iteratorFromEnd -= 1 tupleFromEnd = lStringSizeTuplesSorted[iteratorFromEnd] lStringSizeList.append(lStringSize) lStringSize = [tuple[0]] sumTupleSize = tuple[1] iteratorFromBegin += 1 if lStringSize: lStringSizeList.append(lStringSize) return lStringSizeList