2018-10-12 18:44:36 +02:00
|
|
|
|
|
|
|
|
class drc_lut():
|
|
|
|
|
"""
|
|
|
|
|
Implement a lookup table of rules.
|
|
|
|
|
Each element is a tuple with the last value being the rule.
|
|
|
|
|
It searches through backwards until all of the key values are
|
|
|
|
|
met and returns the rule value.
|
|
|
|
|
For exampe, the key values can be width and length,
|
|
|
|
|
and it would return the rule for a wire of a given width and length.
|
|
|
|
|
A key can be not compared by passing a None.
|
|
|
|
|
"""
|
|
|
|
|
def __init__(self, table):
|
|
|
|
|
self.table = table
|
|
|
|
|
|
2018-10-12 23:37:51 +02:00
|
|
|
def __call__(self, *key):
|
2018-10-12 18:44:36 +02:00
|
|
|
"""
|
|
|
|
|
Lookup a given tuple in the table.
|
|
|
|
|
"""
|
2018-10-12 23:37:51 +02:00
|
|
|
if len(*key)==0:
|
2018-10-12 18:44:36 +02:00
|
|
|
key_size = len(list(self.table.keys())[0])
|
2018-10-12 23:37:51 +02:00
|
|
|
key = tuple(0 for i in range(key_size))
|
|
|
|
|
for table_key in sorted(self.table.keys(), reverse=True):
|
|
|
|
|
if self.match(key, table_key):
|
|
|
|
|
return self.table[table_key]
|
2018-10-12 18:44:36 +02:00
|
|
|
|
|
|
|
|
def match(self, t1, t2):
|
|
|
|
|
"""
|
|
|
|
|
Determine if t1>t2 for each tuple pair.
|
|
|
|
|
"""
|
|
|
|
|
# If any one pair is less than, return False
|
|
|
|
|
for i in range(len(t1)):
|
|
|
|
|
if t1[i] < t2[i]:
|
|
|
|
|
return False
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|