2 typedef unsigned short UINT16;
3 typedef unsigned char BYTE;
4 static UINT16 HuffCodeLOM[] = { 0x0001, 0x0000, 0x0002, 0x0009, 0x0006, 0x0005, 0x000d, 0x000b,
5 0x0003, 0x001b, 0x0007, 0x0017, 0x0037, 0x000f, 0x004f, 0x006f,
6 0x002f, 0x00ef, 0x001f, 0x005f, 0x015f, 0x009f, 0x00df, 0x01df,
7 0x003f, 0x013f, 0x00bf, 0x01bf, 0x007f, 0x017f, 0x00ff, 0x01ff };
9 UINT16 HashTable[32] = { [0 ... 31] = 0xffff };
11 BYTE tab[4] = { 0, 4, 10, 19 };
13 UINT16 hash(UINT16 key)
15 return ((key & 0x1f) ^ (key >> 5) ^ (key >> 9));
18 BYTE minihash(UINT16 key)
22 return ((h ^ (h >> 2) ^ (h >> 3)) & 0x3);
25 void buildhashtable(void)
30 for (i = 0; i < 32; i++)
32 h = hash(HuffCodeLOM[i]);
34 if (HashTable[h] != 0xffff)
36 HashTable[h] ^= (HuffCodeLOM[i] & 0xfe0) ^ 0xfe0;
37 HashTable[tab[minihash(HuffCodeLOM[i])]] = i;
42 HashTable[h] ^= 0xfe0;
45 printf("at %d %" PRIu16 "=0x%" PRIx16 "\n", i, h, HashTable[h]);
49 BYTE getvalue(UINT16 huff)
51 UINT16 h = HashTable[hash(huff)];
58 return HashTable[tab[minihash(huff)]];
65 printf("static UINT16 HuffIndexLOM[32] = {\n");
67 for (i = 0; i < 32; i++)
70 printf("0x%" PRIx16 " };\n", HashTable[i]);
72 printf("0x%" PRIx16 ", ", HashTable[i]);
75 for (i = 0; i < 32; i++)
76 if (i != getvalue(HuffCodeLOM[i]))
77 printf("Fail :( at %d : 0x%04" PRIx16 " got %" PRIu8 "\n", i, HuffCodeLOM[i],
78 getvalue(HuffCodeLOM[i]));