diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2016-09-08 20:24:59 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2016-09-09 15:26:04 -0400 |
commit | 53fc5951dc281511a28dcc1392d9f2fc5662660a (patch) | |
tree | fc1ad62d69b18dda7e02276b8843e302ea263655 | |
parent | 03ab4da2ac19a6cb7653da9a250319f4dff963e9 (diff) | |
download | bfs-53fc5951dc281511a28dcc1392d9f2fc5662660a.tar.xz |
Give case a little bit of weight in the typo metric.
-rw-r--r-- | typo.c | 218 |
1 files changed, 108 insertions, 110 deletions
@@ -14,120 +14,118 @@ #include <stdlib.h> #include <string.h> -struct coords { - int x, y; -}; - // Assume QWERTY layout for now -static const struct coords key_coords[UCHAR_MAX] = { - ['`'] = { 0, 0}, - ['~'] = { 0, 0}, - ['1'] = { 3, 0}, - ['!'] = { 3, 0}, - ['2'] = { 6, 0}, - ['@'] = { 6, 0}, - ['3'] = { 9, 0}, - ['#'] = { 9, 0}, - ['4'] = {12, 0}, - ['$'] = {12, 0}, - ['5'] = {15, 0}, - ['%'] = {15, 0}, - ['6'] = {18, 0}, - ['^'] = {18, 0}, - ['7'] = {21, 0}, - ['&'] = {21, 0}, - ['8'] = {24, 0}, - ['*'] = {24, 0}, - ['9'] = {27, 0}, - ['('] = {27, 0}, - ['0'] = {30, 0}, - [')'] = {30, 0}, - ['-'] = {33, 0}, - ['_'] = {33, 0}, - ['='] = {36, 0}, - ['+'] = {36, 0}, - - ['\t'] = { 1, 3}, - ['q'] = { 4, 3}, - ['Q'] = { 4, 3}, - ['w'] = { 7, 3}, - ['W'] = { 7, 3}, - ['e'] = {10, 3}, - ['E'] = {10, 3}, - ['r'] = {13, 3}, - ['R'] = {13, 3}, - ['t'] = {16, 3}, - ['T'] = {16, 3}, - ['y'] = {19, 3}, - ['Y'] = {19, 3}, - ['u'] = {22, 3}, - ['U'] = {22, 3}, - ['i'] = {25, 3}, - ['I'] = {25, 3}, - ['o'] = {28, 3}, - ['O'] = {28, 3}, - ['p'] = {31, 3}, - ['P'] = {31, 3}, - ['['] = {34, 3}, - ['{'] = {34, 3}, - [']'] = {37, 3}, - ['}'] = {37, 3}, - ['\\'] = {40, 3}, - ['|'] = {40, 3}, - - ['a'] = { 5, 6}, - ['A'] = { 5, 6}, - ['s'] = { 8, 6}, - ['S'] = { 8, 6}, - ['d'] = {11, 6}, - ['D'] = {11, 6}, - ['f'] = {14, 6}, - ['F'] = {14, 6}, - ['g'] = {17, 6}, - ['G'] = {17, 6}, - ['h'] = {20, 6}, - ['H'] = {20, 6}, - ['j'] = {23, 6}, - ['J'] = {23, 6}, - ['k'] = {26, 6}, - ['K'] = {26, 6}, - ['l'] = {29, 6}, - ['L'] = {29, 6}, - [';'] = {32, 6}, - [':'] = {32, 6}, - ['\''] = {35, 6}, - ['"'] = {35, 6}, - ['\n'] = {38, 6}, - - ['z'] = { 6, 9}, - ['Z'] = { 6, 9}, - ['x'] = { 9, 9}, - ['X'] = { 9, 9}, - ['c'] = {12, 9}, - ['C'] = {12, 9}, - ['v'] = {15, 9}, - ['V'] = {15, 9}, - ['b'] = {18, 9}, - ['B'] = {18, 9}, - ['n'] = {21, 9}, - ['N'] = {21, 9}, - ['m'] = {24, 9}, - ['M'] = {24, 9}, - [','] = {27, 9}, - ['<'] = {27, 9}, - ['.'] = {30, 9}, - ['>'] = {30, 9}, - ['/'] = {33, 9}, - ['?'] = {33, 9}, - - [' '] = {18, 12}, +static const int key_coords[UCHAR_MAX][3] = { + ['`'] = { 0, 0, 0}, + ['~'] = { 0, 0, 1}, + ['1'] = { 3, 0, 0}, + ['!'] = { 3, 0, 1}, + ['2'] = { 6, 0, 0}, + ['@'] = { 6, 0, 1}, + ['3'] = { 9, 0, 0}, + ['#'] = { 9, 0, 1}, + ['4'] = {12, 0, 0}, + ['$'] = {12, 0, 1}, + ['5'] = {15, 0, 0}, + ['%'] = {15, 0, 1}, + ['6'] = {18, 0, 0}, + ['^'] = {18, 0, 1}, + ['7'] = {21, 0, 0}, + ['&'] = {21, 0, 1}, + ['8'] = {24, 0, 0}, + ['*'] = {24, 0, 1}, + ['9'] = {27, 0, 0}, + ['('] = {27, 0, 1}, + ['0'] = {30, 0, 0}, + [')'] = {30, 0, 1}, + ['-'] = {33, 0, 0}, + ['_'] = {33, 0, 1}, + ['='] = {36, 0, 0}, + ['+'] = {36, 0, 1}, + + ['\t'] = { 1, 3, 0}, + ['q'] = { 4, 3, 0}, + ['Q'] = { 4, 3, 1}, + ['w'] = { 7, 3, 0}, + ['W'] = { 7, 3, 1}, + ['e'] = {10, 3, 0}, + ['E'] = {10, 3, 1}, + ['r'] = {13, 3, 0}, + ['R'] = {13, 3, 1}, + ['t'] = {16, 3, 0}, + ['T'] = {16, 3, 1}, + ['y'] = {19, 3, 0}, + ['Y'] = {19, 3, 1}, + ['u'] = {22, 3, 0}, + ['U'] = {22, 3, 1}, + ['i'] = {25, 3, 0}, + ['I'] = {25, 3, 1}, + ['o'] = {28, 3, 0}, + ['O'] = {28, 3, 1}, + ['p'] = {31, 3, 0}, + ['P'] = {31, 3, 1}, + ['['] = {34, 3, 0}, + ['{'] = {34, 3, 1}, + [']'] = {37, 3, 0}, + ['}'] = {37, 3, 1}, + ['\\'] = {40, 3, 0}, + ['|'] = {40, 3, 1}, + + ['a'] = { 5, 6, 0}, + ['A'] = { 5, 6, 1}, + ['s'] = { 8, 6, 0}, + ['S'] = { 8, 6, 1}, + ['d'] = {11, 6, 0}, + ['D'] = {11, 6, 1}, + ['f'] = {14, 6, 0}, + ['F'] = {14, 6, 1}, + ['g'] = {17, 6, 0}, + ['G'] = {17, 6, 1}, + ['h'] = {20, 6, 0}, + ['H'] = {20, 6, 1}, + ['j'] = {23, 6, 0}, + ['J'] = {23, 6, 1}, + ['k'] = {26, 6, 0}, + ['K'] = {26, 6, 1}, + ['l'] = {29, 6, 0}, + ['L'] = {29, 6, 1}, + [';'] = {32, 6, 0}, + [':'] = {32, 6, 1}, + ['\''] = {35, 6, 0}, + ['"'] = {35, 6, 1}, + ['\n'] = {38, 6, 0}, + + ['z'] = { 6, 9, 0}, + ['Z'] = { 6, 9, 1}, + ['x'] = { 9, 9, 0}, + ['X'] = { 9, 9, 1}, + ['c'] = {12, 9, 0}, + ['C'] = {12, 9, 1}, + ['v'] = {15, 9, 0}, + ['V'] = {15, 9, 1}, + ['b'] = {18, 9, 0}, + ['B'] = {18, 9, 1}, + ['n'] = {21, 9, 0}, + ['N'] = {21, 9, 1}, + ['m'] = {24, 9, 0}, + ['M'] = {24, 9, 1}, + [','] = {27, 9, 0}, + ['<'] = {27, 9, 1}, + ['.'] = {30, 9, 0}, + ['>'] = {30, 9, 1}, + ['/'] = {33, 9, 0}, + ['?'] = {33, 9, 1}, + + [' '] = {18, 12, 0}, }; static int char_distance(char a, char b) { - const struct coords *ac = &key_coords[(unsigned char)a], *bc = &key_coords[(unsigned char)b]; - int dx = abs(ac->x - bc->x); - int dy = abs(ac->y - bc->y); - return dx + dy; + const int *ac = key_coords[(unsigned char)a], *bc = key_coords[(unsigned char)b]; + int ret = 0; + for (int i = 0; i < 3; ++i) { + ret += abs(ac[i] - bc[i]); + } + return ret; } int typo_distance(const char *actual, const char *expected) { |