예제 #1
0
        ///// <summary>
        ///// 获取下一个节点
        ///// </summary>
        ///// <returns>下一个节点</returns>
        //private static int nextNode()
        //{
        //    int node;
        //    interlocked.CompareSetSleep0NoCheck(ref nodeLock);
        //    if (freeNodes.Count == 0)
        //    {
        //        if (currentNode == nodePool.Length)
        //        {
        //            try
        //            {
        //                newNode[] nodes = new newNode[currentNode << 1];
        //                node = currentNode;
        //                nodePool.CopyTo(nodes, 0);
        //                ++currentNode;
        //                nodePool = nodes;
        //            }
        //            finally { nodeLock = 0; }
        //        }
        //        else
        //        {
        //            node = currentNode++;
        //            nodeLock = 0;
        //        }
        //    }
        //    else
        //    {
        //        nodePool[node = freeNodes.Unsafer.Pop()].Clear();
        //        nodeLock = 0;
        //    }
        //    return node;
        //}
        /// <summary>
        /// 获取根节点
        /// </summary>
        /// <returns>根节点</returns>
        private static int getBootNode()
        {
            int node;

            Monitor.Enter(nodeLock);
            if (freeNodes.Count == 0)
            {
                if (currentNode == NodePool.Length)
                {
                    try
                    {
                        node[] newNodes = new node[currentNode << 1];
                        node = currentNode;
                        NodePool.CopyTo(newNodes, 0);
                        ++currentNode;
                        NodePool = newNodes;
                        newNodes[node].SetNodes();
                    }
                    finally { Monitor.Exit(nodeLock); }
                }
                else
                {
                    NodePool[node = currentNode].SetNodes();
                    ++currentNode;
                    Monitor.Exit(nodeLock);
                }
            }
            else
            {
                NodePool[node = freeNodes.UnsafePop()].SetBoot();
                Monitor.Exit(nodeLock);
            }
            return(node);
        }
예제 #2
0
 /// <summary>
 /// 搜索对象
 /// </summary>
 private void searchValue()
 {
     if (OnValue != null)
     {
         OnValue();
         if (IsStop)
         {
             return;
         }
     }
     if (!values.Contains(Value))
     {
         values.Add(Value);
         if (OnNewValue != null)
         {
             OnNewValue();
             if (IsStop)
             {
                 return;
             }
         }
         hashString typeKey = Value.Type.FullName;
         if (!types.Contains(typeKey))
         {
             types.Add(typeKey);
             if (OnType != null)
             {
                 OnType();
                 if (IsStop)
                 {
                     return;
                 }
             }
         }
         if (Value.Values != null)
         {
             field[] fields = Value.Type.Fields;
             int     index  = 0;
             if (fields == null)
             {
                 foreach (value value in Value.Values)
                 {
                     if (IsStop)
                     {
                         break;
                     }
                     if (value != null)
                     {
                         path.Add(index.toString());
                         Value = value;
                         searchValue();
                         path.UnsafePop();
                     }
                     ++index;
                 }
             }
             else
             {
                 foreach (value value in Value.Values)
                 {
                     if (IsStop)
                     {
                         break;
                     }
                     if (value != null)
                     {
                         path.Add(fields[index].Name);
                         Value = value;
                         searchValue();
                         path.UnsafePop();
                     }
                     ++index;
                 }
             }
         }
     }
 }