lost in explanation: programing problem, transition of maps

By Xah Lee. Date: .

another interesting programing problem i ran into.

so am writing a app that convert keyboard layout diagram in svg. Xah Fly Keys Layout for Kinesis/Ergodox Keyboard

Click a button to show qwerty, or dvorak. Now, am adding colemak. Ends up rewrite my code. Here's the problem.

Suppose you have 2 maps, dvorak to qwerty, and qwerty to colemak. Normally, i keep the map minimal. That is, if a key, such as "a", is same in both qwerty and dvorak, it does not have a entry in the map. Meaning, if no entry found, then use the same key.

But now, that cannot work. Because, suppose i want to convert from dvorak to colemak. Now, you don't have a map for every keymap conversion A to B. Because, suppose you have lots layouts, then your number of map will increase exponentially. 26 x 26.

So instead, you have each and every map map to qwerty only. Let's call this map A. Then, when you want to convert from layout X to Y, you do X to A, then A to Y.

So the map A is the basis map. This way, if you have 26 layouts, you only need 26 maps, not 26x26.

Now now, here's the problem. Now you need to have a function that takes 2 maps, A to B, B to C, and return a new map A to C. So, the code will loop thru keys in AtoB, check if value is in key of BtoC, if so, then you have a new entry, otherwise, no.

But, now, if your map is minimal, such that when key and value are same, then it does not have a entry, then, you got a problem. Because in this transition, you do not actually know, whether it should have a entry or it's assumed to be the same.

Does this make sense?