// import      _                                /**/ from 'lodash'
import type * as TY                                  from '../types.ts'

export const ltrToWordbitsTable: Record<TY.AtoZlo, TY.WordbitsT> = {
  a: 0b00_0000_0000_0000_0000_0000_0001, b: 0b00_0000_0000_0000_0000_0000_0010, c: 0b00_0000_0000_0000_0000_0000_0100, d: 0b00_0000_0000_0000_0000_0000_1000,
  e: 0b00_0000_0000_0000_0000_0001_0000, f: 0b00_0000_0000_0000_0000_0010_0000, g: 0b00_0000_0000_0000_0000_0100_0000, h: 0b00_0000_0000_0000_0000_1000_0000,
  i: 0b00_0000_0000_0000_0001_0000_0000, j: 0b00_0000_0000_0000_0010_0000_0000, k: 0b00_0000_0000_0000_0100_0000_0000, l: 0b00_0000_0000_0000_1000_0000_0000,
  m: 0b00_0000_0000_0001_0000_0000_0000, n: 0b00_0000_0000_0010_0000_0000_0000, o: 0b00_0000_0000_0100_0000_0000_0000, p: 0b00_0000_0000_1000_0000_0000_0000,
  q: 0b00_0000_0001_0000_0000_0000_0000, r: 0b00_0000_0010_0000_0000_0000_0000, s: 0b00_0000_0100_0000_0000_0000_0000, t: 0b00_0000_1000_0000_0000_0000_0000,
  u: 0b00_0001_0000_0000_0000_0000_0000, v: 0b00_0010_0000_0000_0000_0000_0000, w: 0b00_0100_0000_0000_0000_0000_0000, x: 0b00_1000_0000_0000_0000_0000_0000,
  y: 0b01_0000_0000_0000_0000_0000_0000, z: 0b10_0000_0000_0000_0000_0000_0000,
} as const

export const idxToMaskTable32: readonly TY.WordbitsT[] = [
  0b0000_0000_0000_0000_0000_0000_0000_0001, 0b0000_0000_0000_0000_0000_0000_0000_0010, 0b0000_0000_0000_0000_0000_0000_0000_0100, 0b0000_0000_0000_0000_0000_0000_0000_1000, // 1
  0b0000_0000_0000_0000_0000_0000_0001_0000, 0b0000_0000_0000_0000_0000_0000_0010_0000, 0b0000_0000_0000_0000_0000_0000_0100_0000, 0b0000_0000_0000_0000_0000_0000_1000_0000, // 2
  0b0000_0000_0000_0000_0000_0001_0000_0000, 0b0000_0000_0000_0000_0000_0010_0000_0000, 0b0000_0000_0000_0000_0000_0100_0000_0000, 0b0000_0000_0000_0000_0000_1000_0000_0000, // 3
  0b0000_0000_0000_0000_0001_0000_0000_0000, 0b0000_0000_0000_0000_0010_0000_0000_0000, 0b0000_0000_0000_0000_0100_0000_0000_0000, 0b0000_0000_0000_0000_1000_0000_0000_0000, // 4
  0b0000_0000_0000_0001_0000_0000_0000_0000, 0b0000_0000_0000_0010_0000_0000_0000_0000, 0b0000_0000_0000_0100_0000_0000_0000_0000, 0b0000_0000_0000_1000_0000_0000_0000_0000, // 5
  0b0000_0000_0001_0000_0000_0000_0000_0000, 0b0000_0000_0010_0000_0000_0000_0000_0000, 0b0000_0000_0100_0000_0000_0000_0000_0000, 0b0000_0000_1000_0000_0000_0000_0000_0000, // 6
  0b0000_0001_0000_0000_0000_0000_0000_0000, 0b0000_0010_0000_0000_0000_0000_0000_0000, 0b0000_0100_0000_0000_0000_0000_0000_0000, 0b0000_1000_0000_0000_0000_0000_0000_0000, // 7
  0b0001_0000_0000_0000_0000_0000_0000_0000, 0b0010_0000_0000_0000_0000_0000_0000_0000, 0b0100_0000_0000_0000_0000_0000_0000_0000, 0b1000_0000_0000_0000_0000_0000_0000_0000, // 8
] as const

/** Lookup for bits 0 to 6 (abcdefg) of Wordbits to the specific uniq letters they encode */
export const abcdefgFor00_06: readonly TY.Shingle[] = [
  '',      'a',      'b',      'ab',      'c',      'ac',      'bc',      'abc',
  'd',     'ad',     'bd',     'abd',     'cd',     'acd',     'bcd',     'abcd',
  'e',     'ae',     'be',     'abe',     'ce',     'ace',     'bce',     'abce',
  'de',    'ade',    'bde',    'abde',    'cde',    'acde',    'bcde',    'abcde',
  'f',     'af',     'bf',     'abf',     'cf',     'acf',     'bcf',     'abcf',
  'df',    'adf',    'bdf',    'abdf',    'cdf',    'acdf',    'bcdf',    'abcdf',
  'ef',    'aef',    'bef',    'abef',    'cef',    'acef',    'bcef',    'abcef',
  'def',   'adef',   'bdef',   'abdef',   'cdef',   'acdef',   'bcdef',   'abcdef',
  'g',     'ag',     'bg',     'abg',     'cg',     'acg',     'bcg',     'abcg',
  'dg',    'adg',    'bdg',    'abdg',    'cdg',    'acdg',    'bcdg',    'abcdg',
  'eg',    'aeg',    'beg',    'abeg',    'ceg',    'aceg',    'bceg',    'abceg',
  'deg',   'adeg',   'bdeg',   'abdeg',   'cdeg',   'acdeg',   'bcdeg',   'abcdeg',
  'fg',    'afg',    'bfg',    'abfg',    'cfg',    'acfg',    'bcfg',    'abcfg',
  'dfg',   'adfg',   'bdfg',   'abdfg',   'cdfg',   'acdfg',   'bcdfg',   'abcdfg',
  'efg',   'aefg',   'befg',   'abefg',   'cefg',   'acefg',   'bcefg',   'abcefg',
  'defg',  'adefg',  'bdefg',  'abdefg',  'cdefg',  'acdefg',  'bcdefg',  'abcdefg',
]
/** Lookup for bits 7 to 13 (hijklmn) of Wordbits to the specific uniq letters they encode */
export const hijklmnFor07_13: readonly TY.Shingle[] = [
  '',      'h',      'i',      'hi',      'j',      'hj',      'ij',      'hij',
  'k',     'hk',     'ik',     'hik',     'jk',     'hjk',     'ijk',     'hijk',
  'l',     'hl',     'il',     'hil',     'jl',     'hjl',     'ijl',     'hijl',
  'kl',    'hkl',    'ikl',    'hikl',    'jkl',    'hjkl',    'ijkl',    'hijkl',
  'm',     'hm',     'im',     'him',     'jm',     'hjm',     'ijm',     'hijm',
  'km',    'hkm',    'ikm',    'hikm',    'jkm',    'hjkm',    'ijkm',    'hijkm',
  'lm',    'hlm',    'ilm',    'hilm',    'jlm',    'hjlm',    'ijlm',    'hijlm',
  'klm',   'hklm',   'iklm',   'hiklm',   'jklm',   'hjklm',   'ijklm',   'hijklm',
  'n',     'hn',     'in',     'hin',     'jn',     'hjn',     'ijn',     'hijn',
  'kn',    'hkn',    'ikn',    'hikn',    'jkn',    'hjkn',    'ijkn',    'hijkn',
  'ln',    'hln',    'iln',    'hiln',    'jln',    'hjln',    'ijln',    'hijln',
  'kln',   'hkln',   'ikln',   'hikln',   'jkln',   'hjkln',   'ijkln',   'hijkln',
  'mn',    'hmn',    'imn',    'himn',    'jmn',    'hjmn',    'ijmn',    'hijmn',
  'kmn',   'hkmn',   'ikmn',   'hikmn',   'jkmn',   'hjkmn',   'ijkmn',   'hijkmn',
  'lmn',   'hlmn',   'ilmn',   'hilmn',   'jlmn',   'hjlmn',   'ijlmn',   'hijlmn',
  'klmn',  'hklmn',  'iklmn',  'hiklmn',  'jklmn',  'hjklmn',  'ijklmn',  'hijklmn',
]
/** Lookup for bits 14 to 20 (opqrstu) of Wordbits to the specific uniq letters they encode */
export const opqrstuFor14_20: readonly TY.Shingle[] = [
  '',      'o',      'p',      'op',      'q',      'oq',      'pq',      'opq',
  'r',     'or',     'pr',     'opr',     'qr',     'oqr',     'pqr',     'opqr',
  's',     'os',     'ps',     'ops',     'qs',     'oqs',     'pqs',     'opqs',
  'rs',    'ors',    'prs',    'oprs',    'qrs',    'oqrs',    'pqrs',    'opqrs',
  't',     'ot',     'pt',     'opt',     'qt',     'oqt',     'pqt',     'opqt',
  'rt',    'ort',    'prt',    'oprt',    'qrt',    'oqrt',    'pqrt',    'opqrt',
  'st',    'ost',    'pst',    'opst',    'qst',    'oqst',    'pqst',    'opqst',
  'rst',   'orst',   'prst',   'oprst',   'qrst',   'oqrst',   'pqrst',   'opqrst',
  'u',     'ou',     'pu',     'opu',     'qu',     'oqu',     'pqu',     'opqu',
  'ru',    'oru',    'pru',    'opru',    'qru',    'oqru',    'pqru',    'opqru',
  'su',    'osu',    'psu',    'opsu',    'qsu',    'oqsu',    'pqsu',    'opqsu',
  'rsu',   'orsu',   'prsu',   'oprsu',   'qrsu',   'oqrsu',   'pqrsu',   'opqrsu',
  'tu',    'otu',    'ptu',    'optu',    'qtu',    'oqtu',    'pqtu',    'opqtu',
  'rtu',   'ortu',   'prtu',   'oprtu',   'qrtu',   'oqrtu',   'pqrtu',   'opqrtu',
  'stu',   'ostu',   'pstu',   'opstu',   'qstu',   'oqstu',   'pqstu',   'opqstu',
  'rstu',  'orstu',  'prstu',  'oprstu',  'qrstu',  'oqrstu',  'pqrstu',  'opqrstu',
]
/** Lookup for bits 21 to 25 (vwxyz) of Wordbits to the specific uniq letters they encode */
export const   vwxyzFor21_25: readonly TY.Shingle[] = [
  '',      'v',      'w',      'vw',      'x',      'vx',      'wx',      'vwx',
  'y',     'vy',     'wy',     'vwy',     'xy',     'vxy',     'wxy',     'vwxy',
  'z',     'vz',     'wz',     'vwz',     'xz',     'vxz',     'wxz',     'vwxz',
  'yz',    'vyz',    'wzy',    'vwzy',    'xyz',    'vxyz',    'wxyz',    'vwxyz',
]

/** utility for pretty-printing binary numbers; 8 bit segments */
export const prettyBinaryTable8: string[] = [
  '0000_0000',  '0000_0001',  '0000_0010',  '0000_0011',  '0000_0100',  '0000_0101',  '0000_0110',  '0000_0111', '0000_1000',  '0000_1001',  '0000_1010',  '0000_1011',  '0000_1100',  '0000_1101',  '0000_1110',  '0000_1111',
  '0001_0000',  '0001_0001',  '0001_0010',  '0001_0011',  '0001_0100',  '0001_0101',  '0001_0110',  '0001_0111', '0001_1000',  '0001_1001',  '0001_1010',  '0001_1011',  '0001_1100',  '0001_1101',  '0001_1110',  '0001_1111',
  '0010_0000',  '0010_0001',  '0010_0010',  '0010_0011',  '0010_0100',  '0010_0101',  '0010_0110',  '0010_0111', '0010_1000',  '0010_1001',  '0010_1010',  '0010_1011',  '0010_1100',  '0010_1101',  '0010_1110',  '0010_1111',
  '0011_0000',  '0011_0001',  '0011_0010',  '0011_0011',  '0011_0100',  '0011_0101',  '0011_0110',  '0011_0111', '0011_1000',  '0011_1001',  '0011_1010',  '0011_1011',  '0011_1100',  '0011_1101',  '0011_1110',  '0011_1111',
  '0100_0000',  '0100_0001',  '0100_0010',  '0100_0011',  '0100_0100',  '0100_0101',  '0100_0110',  '0100_0111', '0100_1000',  '0100_1001',  '0100_1010',  '0100_1011',  '0100_1100',  '0100_1101',  '0100_1110',  '0100_1111',
  '0101_0000',  '0101_0001',  '0101_0010',  '0101_0011',  '0101_0100',  '0101_0101',  '0101_0110',  '0101_0111', '0101_1000',  '0101_1001',  '0101_1010',  '0101_1011',  '0101_1100',  '0101_1101',  '0101_1110',  '0101_1111',
  '0110_0000',  '0110_0001',  '0110_0010',  '0110_0011',  '0110_0100',  '0110_0101',  '0110_0110',  '0110_0111', '0110_1000',  '0110_1001',  '0110_1010',  '0110_1011',  '0110_1100',  '0110_1101',  '0110_1110',  '0110_1111',
  '0111_0000',  '0111_0001',  '0111_0010',  '0111_0011',  '0111_0100',  '0111_0101',  '0111_0110',  '0111_0111', '0111_1000',  '0111_1001',  '0111_1010',  '0111_1011',  '0111_1100',  '0111_1101',  '0111_1110',  '0111_1111',
  '1000_0000',  '1000_0001',  '1000_0010',  '1000_0011',  '1000_0100',  '1000_0101',  '1000_0110',  '1000_0111', '1000_1000',  '1000_1001',  '1000_1010',  '1000_1011',  '1000_1100',  '1000_1101',  '1000_1110',  '1000_1111',
  '1001_0000',  '1001_0001',  '1001_0010',  '1001_0011',  '1001_0100',  '1001_0101',  '1001_0110',  '1001_0111', '1001_1000',  '1001_1001',  '1001_1010',  '1001_1011',  '1001_1100',  '1001_1101',  '1001_1110',  '1001_1111',
  '1010_0000',  '1010_0001',  '1010_0010',  '1010_0011',  '1010_0100',  '1010_0101',  '1010_0110',  '1010_0111', '1010_1000',  '1010_1001',  '1010_1010',  '1010_1011',  '1010_1100',  '1010_1101',  '1010_1110',  '1010_1111',
  '1011_0000',  '1011_0001',  '1011_0010',  '1011_0011',  '1011_0100',  '1011_0101',  '1011_0110',  '1011_0111', '1011_1000',  '1011_1001',  '1011_1010',  '1011_1011',  '1011_1100',  '1011_1101',  '1011_1110',  '1011_1111',
  '1100_0000',  '1100_0001',  '1100_0010',  '1100_0011',  '1100_0100',  '1100_0101',  '1100_0110',  '1100_0111', '1100_1000',  '1100_1001',  '1100_1010',  '1100_1011',  '1100_1100',  '1100_1101',  '1100_1110',  '1100_1111',
  '1101_0000',  '1101_0001',  '1101_0010',  '1101_0011',  '1101_0100',  '1101_0101',  '1101_0110',  '1101_0111', '1101_1000',  '1101_1001',  '1101_1010',  '1101_1011',  '1101_1100',  '1101_1101',  '1101_1110',  '1101_1111',
  '1110_0000',  '1110_0001',  '1110_0010',  '1110_0011',  '1110_0100',  '1110_0101',  '1110_0110',  '1110_0111', '1110_1000',  '1110_1001',  '1110_1010',  '1110_1011',  '1110_1100',  '1110_1101',  '1110_1110',  '1110_1111',
  '1111_0000',  '1111_0001',  '1111_0010',  '1111_0011',  '1111_0100',  '1111_0101',  '1111_0110',  '1111_0111', '1111_1000',  '1111_1001',  '1111_1010',  '1111_1011',  '1111_1100',  '1111_1101',  '1111_1110',  '1111_1111',
]
/** utility for pretty-printing binary numbers; 4 bit segments */
export const prettyBinaryTable4: string[] = [
  '0000', '0001', '0010', '0011', '0100', '0101', '0110', '0111',
  '1000', '1001', '1010', '1011', '1100', '1101', '1110', '1111',
]
/** utility for pretty-printing binary numbers; 2 bit segments */
export const prettyBinaryTable2: string[] = [
  '00', '01', '10', '11',
]