Exemple #1
0
            /// <summary>
            /// 创建 Trie 图
            /// </summary>
            /// <param name="staticGraph"></param>
            /// <param name="graph"></param>
            internal void Create(StaticStringTrieGraph staticGraph, StringTrieGraph graph)
            {
                cache = DictionaryCreator.CreateOnly <StringTrieGraph.Node, int>();
                StringTrieGraph.Node boot = graph.Boot;
                bool isCreate             = false;

                Monitor.Enter(NodePool.Lock);
                try
                {
                    staticGraph.setBoot(create(boot));
                    createLink(boot);
                    isCreate = true;
                }
                finally
                {
                    if (isCreate || cache == null)
                    {
                        Monitor.Exit(NodePool.Lock);
                    }
                    else
                    {
                        try
                        {
                            staticGraph.CancelBuilder();
                            foreach (int index in cache.Values)
                            {
                                if (index == nodeIndex)
                                {
                                    nodeIndex = 0;
                                }
                                NodePool.Pool[index >> ArrayPool.ArraySizeBit][index & ArrayPool.ArraySizeAnd].CancelBuilder();
                            }
                            NodePool.FreeNoLock(cache.Values);
                            if (nodeIndex != 0)
                            {
                                NodePool.Pool[nodeIndex >> ArrayPool.ArraySizeBit][nodeIndex & ArrayPool.ArraySizeAnd].CancelBuilder();
                                NodePool.FreeNoLock(nodeIndex);
                            }
                        }
                        finally { Monitor.Exit(NodePool.Lock); }
                    }
                }
            }
 /// <summary>
 /// 创建 Trie 图
 /// </summary>
 /// <param name="trieGraph">字符串 Trie 图</param>
 /// <param name="isCopyCharTypeData">是否复制分词字符类型数据</param>
 internal void Create(StringTrieGraph trieGraph, bool isCopyCharTypeData)
 {
     if (trieGraph.Boot.Nodes.count() != 0)
     {
         new Builder().Create(this, trieGraph);
     }
     if (trieGraph.CharTypeData.Data != CharTypeData.Data && CharTypeData.Data != null)
     {
         if (isCopyCharTypeData)
         {
             AutoCSer.Memory.Common.CopyNotNull(trieGraph.CharTypeData.Byte, (CharTypeData = Unmanaged.GetPointer(1 << 16, false)).Byte, 1 << 16);
         }
         else
         {
             CharTypeData           = trieGraph.CharTypeData;
             trieGraph.CharTypeData = new AutoCSer.Memory.Pointer {
                 Data = StringTrieGraph.DefaultCharTypeData.Data
             };
         }
     }
     AnyHeadChar = trieGraph.AnyHeadChar;
 }