WordDictionary.cs裡的bug

Aug 19, 2011 at 9:26 AM
Edited Aug 22, 2011 at 1:46 AM

我覺得第471行附近要改成如下,

 

                if (key.Length == 1)
                {
                    if (!_FirstCharDict.ContainsKey(key[0]))
                    {
                        _FirstCharDict.Add(key[0], wa);
                    }
                    continue;
                }

                if (key.Length == 2)
                {
                    uint doubleChar = ((uint)key[0] * 65536) + key[1];
                    if (!_DoubleCharDict.ContainsKey(doubleChar))
                    {
                        _DoubleCharDict.Add(doubleChar, wa);
                    }
                    continue;
                }

 

就是那2個continue要往外移
不然字典理若有重覆的二字詞的話, 程式就會報錯,
來到第494行就會報錯,

long tripleChar = ((long)key[0]) * 0x100000000 + (uint)(key[1] * 65536) + key[2];

因為根本不會有key[2],
請確認, 感謝!