annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
1 class LauncherUtils(object):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
2
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
3 @staticmethod
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
4 def createHomogeneousSizeList(lStringSizeTuples, maxSize):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
5 lStringSizeTuplesSorted = sorted(lStringSizeTuples, key=lambda stringSizeTuple:(stringSizeTuple[1], stringSizeTuple[0]), reverse = True)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
6 lStringSizeList = []
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
7 lStringSize = []
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
8 sumTupleSize = 0
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
9 iteratorFromBegin = 0
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
10 iteratorFromEnd = len(lStringSizeTuplesSorted) - 1
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
11 for tuple in lStringSizeTuplesSorted:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
12 if sumTupleSize + tuple[1] < maxSize:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
13 lStringSize.append(tuple[0])
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
14 sumTupleSize += tuple[1]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
15 elif tuple[1] >= maxSize:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
16 lStringSizeList.append([tuple[0]])
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
17 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
18 tupleFromEnd = lStringSizeTuplesSorted[iteratorFromEnd]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
19 while sumTupleSize + tupleFromEnd[1] < maxSize and iteratorFromBegin < iteratorFromEnd:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
20 lStringSize.append(tupleFromEnd[0])
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
21 sumTupleSize += tupleFromEnd[1]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
22 del lStringSizeTuplesSorted[iteratorFromEnd]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
23 iteratorFromEnd -= 1
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
24 tupleFromEnd = lStringSizeTuplesSorted[iteratorFromEnd]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
25 lStringSizeList.append(lStringSize)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
26 lStringSize = [tuple[0]]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
27 sumTupleSize = tuple[1]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
28 iteratorFromBegin += 1
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
29 if lStringSize:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
30 lStringSizeList.append(lStringSize)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
31 return lStringSizeList