But then you just iterate to convert everything to meters since you only need to do this once it being inefficient isn't really a concern.
twoWayMap[a][b] = c; twoWayMap[b][a] = 1/c
so your list is easily worked with.keyUnit = twoWayMap.keys.Any()
), doesn't really matter which.toKeyUnitMap[keyUnit] = 1
possibleDirectMap = twoWayMap.keys.Filter(key, value => toKeyUnitMap.hasKey(key))
twoWayMap
isn't empty and actually added new units to toKeyUnitMap
loop back to step 4 and repeat.Since you only do this once you don't need to build anything complicated, you can flatten it with just a 2d dictionary for the existing conversions and a single 1d dict for the final factors.