Skip to content

Commit 8e01968

Browse files
committed
used OrderedDict instead of sort
1 parent b522e99 commit 8e01968

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

find-cycles

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import os
1111
import sys
1212
import json
13-
import collections
13+
from collections import defaultdict, OrderedDict
1414
from typing import List, Set, Dict, Optional
1515

1616
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
@@ -65,7 +65,7 @@ def main():
6565
#print(api_name)
6666
filename = os.path.join(apiload.WIN32JSON_API_DIR, api_name + ".json")
6767
with open(filename, "r", encoding='utf-8-sig') as file:
68-
api = json.load(file)
68+
api = json.load(file, object_pairs_hook=OrderedDict)
6969
constants = api["Constants"]
7070
types = api["Types"]
7171
functions = api["Functions"]
@@ -182,7 +182,7 @@ def main():
182182

183183
print("searching for cycles...")
184184
full_type_set: Set[ApiRef] = set()
185-
api_cycle_type_set: Dict[ApiRef,List[ApiRef]] = {}
185+
api_cycle_type_set: OrderedDict[ApiRef,List[ApiRef]] = {}
186186
#self_cycle_type_set: Dict[ApiRef,List[ApiRef]] = {}
187187

188188
def addApiCycleType(type_set, t, cycle):
@@ -231,7 +231,8 @@ def main():
231231
#print("{} types have self-referential cycles".format(len(self_cycle_type_set)))
232232

233233
api_types_list = list(api_cycle_type_set)
234-
api_types_list.sort()
234+
# I don't think I need to sort anymore since moving to OrderedDict
235+
#api_types_list.sort()
235236
with open(os.path.join(SCRIPT_DIR, "out_cycle_types.txt"), "w") as file:
236237
for cycle_type in api_types_list:
237238
file.write("{}\n".format(cycle_type))
@@ -247,7 +248,7 @@ def main():
247248
# NOTE: this is not all the cycles, just some of the for now
248249
with open(os.path.join(SCRIPT_DIR, "out_cycle_types.dot"), "w") as file:
249250
file.write("digraph type_cycles {\n")
250-
links = collections.defaultdict(set)
251+
links = defaultdict(set)
251252
def addLink(links, a, b):
252253
link_set = links[a]
253254
if b not in link_set:

split

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33
import sys
44
import json
5+
from collections import OrderedDict
56
from typing import List, Set, Dict, Optional
67

78
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
@@ -11,7 +12,10 @@ from out_cycle_types import CYCLE_TYPES
1112

1213
def main():
1314
apis = apiload.loadSortedList()
14-
for api in apis:
15-
print(api)
15+
for api_name in apis:
16+
print(api_name)
17+
filename = os.path.join(apiload.WIN32JSON_API_DIR, api_name + ".json")
18+
with open(filename, "r", encoding='utf-8-sig') as file:
19+
api = json.load(file, object_pairs_hook=OrderedDict)
1620

1721
main()

0 commit comments

Comments
 (0)