コード例 #1
0
ファイル: GlyphNode.cs プロジェクト: xwyangjshb/qizmt
 public void EatWord(IList <byte> word, int index)
 {
     if (nodtype != SearchType_FLAT)
     {
         throw new Exception("node type must be FLAT for this operation");
     }
     if (index >= word.Count)
     {
         return;
     }
     else
     {
         byte newGlyph    = word[index];
         bool contains_ch = ContainsChild(newGlyph);
         if (!contains_ch)
         {
             bool is_leaf = false;
             if (index == word.Count - 1)
             {
                 is_leaf = true;
             }
             AppendChild(newGlyph, is_leaf, word);
         }
         GlyphNode newGlyphNode = SelectChild(newGlyph);
         newGlyphNode.EatWord(word, index + 1);
     }
 }
コード例 #2
0
        public MdoDistro(IList <IList <byte> > samples, int iMajorCount, int iMinorCount)
        {
            if (samples.Count > 0)
            {
                m_iSampleKeyLength = samples[0].Count;
            }
            m_iMajorCount = iMajorCount;
            m_iMinorCount = iMinorCount;
            iSampleCount  = samples.Count;
            for (int i = 0; i < iSampleCount; i++)
            {
                if (samples[i].Count != m_iSampleKeyLength)
                {
                    // Fail case...
                    StringBuilder keysb = new StringBuilder(samples[i].Count);
                    for (int ki = 0; ki < samples[i].Count; ki++)
                    {
                        if (keysb.Length > 0)
                        {
                            keysb.Append(',');
                        }
                        keysb.Append((byte)samples[i][ki]);
                    }
                    throw new Exception("Not all samples have the same key length (expected " + m_iSampleKeyLength.ToString() + ", got " + samples[i].Count.ToString() + "). Consider recreate input or delete cache file if caching on. {key=" + keysb.ToString() + "}");
                }
                IList <byte> word = samples[i];
                tree.EatWord(word, 0);
            }
            GlyphNode.IndexNodes(tree);

            try
            {
                GlyphNode.leaf_nodes.Sort(new cmprGlyphNode());

                PartitionMajorAndMinor(GlyphNode.leaf_nodes, m_iMajorCount, m_iMinorCount);

                GlyphNode.leaf_nodes = null; // Not needed anymore.
            }
            catch
            {
            }
        }