コード例 #1
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
            {
            }
        }