Mercurial > repos > yufei-luo > s_mart
view commons/core/launcher/LauncherUtils.py @ 18:94ab73e8a190
Uploaded
author | m-zytnicki |
---|---|
date | Mon, 29 Apr 2013 03:20:15 -0400 |
parents | 769e306b7933 |
children |
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