Mercurial > repos > yufei-luo > s_mart
view commons/core/launcher/LauncherUtils.py @ 16:6135c3075bc5
Deleted selected files
author | m-zytnicki |
---|---|
date | Mon, 22 Apr 2013 11:09:41 -0400 |
parents | 769e306b7933 |
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