6
|
1 class LauncherUtils(object):
|
|
2
|
|
3 @staticmethod
|
|
4 def createHomogeneousSizeList(lStringSizeTuples, maxSize):
|
|
5 lStringSizeTuplesSorted = sorted(lStringSizeTuples, key=lambda stringSizeTuple:(stringSizeTuple[1], stringSizeTuple[0]), reverse = True)
|
|
6 lStringSizeList = []
|
|
7 lStringSize = []
|
|
8 sumTupleSize = 0
|
|
9 iteratorFromBegin = 0
|
|
10 iteratorFromEnd = len(lStringSizeTuplesSorted) - 1
|
|
11 for tuple in lStringSizeTuplesSorted:
|
|
12 if sumTupleSize + tuple[1] < maxSize:
|
|
13 lStringSize.append(tuple[0])
|
|
14 sumTupleSize += tuple[1]
|
|
15 elif tuple[1] >= maxSize:
|
|
16 lStringSizeList.append([tuple[0]])
|
|
17 else:
|
|
18 tupleFromEnd = lStringSizeTuplesSorted[iteratorFromEnd]
|
|
19 while sumTupleSize + tupleFromEnd[1] < maxSize and iteratorFromBegin < iteratorFromEnd:
|
|
20 lStringSize.append(tupleFromEnd[0])
|
|
21 sumTupleSize += tupleFromEnd[1]
|
|
22 del lStringSizeTuplesSorted[iteratorFromEnd]
|
|
23 iteratorFromEnd -= 1
|
|
24 tupleFromEnd = lStringSizeTuplesSorted[iteratorFromEnd]
|
|
25 lStringSizeList.append(lStringSize)
|
|
26 lStringSize = [tuple[0]]
|
|
27 sumTupleSize = tuple[1]
|
|
28 iteratorFromBegin += 1
|
|
29 if lStringSize:
|
|
30 lStringSizeList.append(lStringSize)
|
|
31 return lStringSizeList |