example lookup in jtiny.table
inch yard
1 * 2.54
baseunit = centimeter
1 * 3 * 12 * 2.54
baseunit = centimeter
psuedo code for looking up the conversion factors of two units, key1 and key2
int index = 0;
int totalfactor1 = 1;
string baseunit1 = key1;
while ( (unitmap.unit myunit = map.get(baseunit1)) != null)
{
if (-t is on)
print "baseunit1 = myunit.factor myunit.baseunit";
totalfactor *= myunit.factor;
baseunit1 = myunit.baseunit;
index++
check the index
}
index = 0;
do same thing for key2
at the end you have
baseunit1, baseunit2
totalfactor1, totalfactor2
make sure baseunit1 and baseunit2 are the same
double myfactor1 = totalfactor1/totalfactor2;
double myfactor2 = totalfactor2/totalfactor1;
print "key1 = myfactor1 key2"
print "key2 = myfactor2 key1"