mirror of https://github.com/openXC7/prjxray.git
Do not sort already ordered data.
Signed-off-by: Keith Rothman <537074+litghost@users.noreply.github.com>
This commit is contained in:
parent
2339c0715e
commit
822a61e2f6
|
|
@ -5,7 +5,6 @@ import re
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from ordered_set import OrderedSet
|
|
||||||
|
|
||||||
|
|
||||||
def extract_numbers(s):
|
def extract_numbers(s):
|
||||||
|
|
@ -40,15 +39,15 @@ def sort(data):
|
||||||
... })
|
... })
|
||||||
>>> for t in o:
|
>>> for t in o:
|
||||||
... print(t+':', o[t])
|
... print(t+':', o[t])
|
||||||
t1: OrderedSet(['b', 'c'])
|
t1: ('b', 'c')
|
||||||
t2: ('a2', 'a10', 'e')
|
t2: ('a2', 'a10', 'e')
|
||||||
t3: (2, 3, 5)
|
t3: (5, 3, 2)
|
||||||
t4: OrderedDict([('a2', ('c0', 'c1', 'c2', 'c10')), ('a4', ('b2', 'b3'))])
|
t4: OrderedDict([('a2', ('c1', 'c2', 'c0', 'c10')), ('a4', ('b2', 'b3'))])
|
||||||
t5: ('a1b1', 'a1b5', 'a2b1')
|
t5: ('a1b5', 'a2b1', 'a1b1')
|
||||||
|
|
||||||
Don't mangle "pairs"
|
Don't mangle "pairs"
|
||||||
>>> sort([('b', 'c'), ('2', '1')])
|
>>> sort([('b', 'c'), ('2', '1')])
|
||||||
[('b', 'c'), ('2', '1')]
|
(('b', 'c'), ('2', '1'))
|
||||||
"""
|
"""
|
||||||
# FIXME: We assume that a list is a tileconn.json format...
|
# FIXME: We assume that a list is a tileconn.json format...
|
||||||
if isinstance(data, list) and len(data) > 0 and 'wire_pairs' in data[0]:
|
if isinstance(data, list) and len(data) > 0 and 'wire_pairs' in data[0]:
|
||||||
|
|
@ -88,29 +87,9 @@ def sort(data):
|
||||||
return new_dict
|
return new_dict
|
||||||
|
|
||||||
elif isinstance(o, set):
|
elif isinstance(o, set):
|
||||||
nitems = []
|
return tuple(sorted(o))
|
||||||
for k in o:
|
|
||||||
nitems.append((key(k), k))
|
|
||||||
nitems.sort(key=lambda n: n[0])
|
|
||||||
|
|
||||||
new_set = OrderedSet()
|
|
||||||
for _, k in nitems:
|
|
||||||
new_set.add(k)
|
|
||||||
return new_set
|
|
||||||
|
|
||||||
elif isinstance(o, (tuple, list)):
|
elif isinstance(o, (tuple, list)):
|
||||||
if len(o) == 2:
|
return tuple(o)
|
||||||
return o
|
|
||||||
|
|
||||||
nlist = []
|
|
||||||
for i in o:
|
|
||||||
nlist.append((key(i), rsorter(i)))
|
|
||||||
nlist.sort(key=lambda n: n[0])
|
|
||||||
|
|
||||||
new_list = []
|
|
||||||
for _, i in nlist:
|
|
||||||
new_list.append(i)
|
|
||||||
return tuple(new_list)
|
|
||||||
else:
|
else:
|
||||||
return o
|
return o
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue