-
Notifications
You must be signed in to change notification settings - Fork 60
/
sorter.py
45 lines (35 loc) · 1.55 KB
/
sorter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
def tosortedlist(changeentrymap):
sortedlist = []
expectedlistsize = len(__aslist(changeentrymap))
while len(sortedlist) < expectedlistsize:
firstentryfromeachkey = __getfirstentryfromeachkeyasmap(changeentrymap)
changesetwithearliestdate = __getchangeentrywithearliestdate(firstentryfromeachkey)
__deleteentry(changeentrymap, changesetwithearliestdate)
sortedlist.append(changesetwithearliestdate)
return sortedlist
def __getfirstentryfromeachkeyasmap(changeentrymap):
firstentries = {}
for key in changeentrymap.keys():
changeentries = changeentrymap.get(key)
if changeentries:
firstentries[key] = changeentries[0]
return firstentries
def __deleteentry(changeentrymap, changeentrytodelete):
for key in changeentrymap.keys():
changeentries = changeentrymap.get(key)
if changeentries and changeentrytodelete.revision is changeentries[0].revision:
changeentries.remove(changeentrytodelete)
break
def __getchangeentrywithearliestdate(changeentries):
changeentrywithearliestdate = None
for key in changeentries.keys():
changeentry = changeentries.get(key)
if not changeentrywithearliestdate or changeentry.date < changeentrywithearliestdate.date:
changeentrywithearliestdate = changeentry
return changeentrywithearliestdate
def __aslist(anymap):
resultlist = []
for key in anymap.keys():
for changeentry in anymap.get(key):
resultlist.append(changeentry)
return resultlist